我用的是jQuery手机。
我如何使页脚消失,而滚动是活跃的?
当滚动停止时,我想再次显示页脚。
HTML片段如下所示:
<div id="footer" data-role="footer" data-position="fixed" data-corners="false">发布于 2014-09-03 09:22:31
var pageIsScrolling = (function(){
var timer, body = $(document.body);
return function(){
clearTimeout(timer);
timer = setTimeout(scrollEnd, 250);
body .addClass('scrolling');
}
function scrollEnd(){
timer = null;
body.removeClass('scrolling');
}
})();
$(window).on('scroll.scrolling', pageIsScrolling);现在,无论何时开始滚动,主体都有类scrolling,您可以在CSS中将其作为目标,如下所示:
.scrolling > footer{ opacity:0; }甚至为您的页脚添加过渡,这样它看起来会更流畅。
(我确信这也适用于jQuery手机)
注:
footer元素,但我认为使用通用状态类是在应用程序中更改状态的更好方法,然后您可以从它中派生出您想要的任何内容,因此,这里需要的状态类是“滚动”。scrollEnd函数是分开的,为了更好的可读性,不直接在setTimeout中编写。发布于 2014-09-03 09:33:35
使用$.scroll在滚动时隐藏页脚,setTimeout在滚动停止时再次显示它:
var scrolling;
$(window).scroll(function() {
clearTimeout(scrolling);//clear any existing timeout
$("#footer").hide();
scrolling = setTimeout(function(){$("#footer").show();},100);//set the timeout to hide the footer (will be cancelled if scrolling continues)
})发布于 2014-09-03 09:17:59
使用jquery滚动事件。
您可以在docs:http://api.jquery.com/scroll/中找到信息。
类似于(没有测试的)的东西:
$(window).scroll(function() {
$("#footer").hide();
});https://stackoverflow.com/questions/25640503
复制相似问题