0
我有這個腳本工作幾乎不錯,但由於某種原因,一秒鐘後滾動頁眉重新添加。爲什麼?我無法弄清楚。隱藏標題滾動向下/顯示在滾動
這裏是我的榜樣https://jsfiddle.net/wg8zv95f/
這裏是原始腳本http://jsfiddle.net/mariusc23/s6mLJ/31/
$(document).ready(function() {
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var headerContainer = $('#header');
var navbarHeight = headerContainer.outerHeight();
$(window).scroll(function(event) {
didScroll = true;
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var st = $(this).scrollTop();
// Make sure they scroll more than delta
if (Math.abs(lastScrollTop - st) <= delta)
return;
// If they scrolled down and are past the navbar, add class .nav-up.
// This is necessary so you never see what is "behind" the navbar.
if (st > lastScrollTop && st > navbarHeight) {
// Scroll Down
headerContainer.removeClass('slideInDown').addClass('fadeOutUp');
} else {
// Scroll Up
if (st + $(window).height() < $(document).height()) {
headerContainer.removeClass('fadeOutUp').addClass('slideInDown');
}
}
lastScrollTop = st;
}
});
CSS
header {
position: fixed;
width: 100%;
animation-duration: 0.8s;
z-index: 99999;
}