Javascript JQuery浮动菜单栏、滚动位置和延迟
我正在制作一个菜单栏,我对JQuery还相当陌生。我希望菜单栏在向下滚动时延迟,但在向上滚动时,我希望它毫不延迟地粘贴到浏览器窗口的顶部。现在两侧的延迟相同,当滚动到顶部时,没有延迟 我希望有人能帮我:)Javascript JQuery浮动菜单栏、滚动位置和延迟,javascript,jquery,Javascript,Jquery,我正在制作一个菜单栏,我对JQuery还相当陌生。我希望菜单栏在向下滚动时延迟,但在向上滚动时,我希望它毫不延迟地粘贴到浏览器窗口的顶部。现在两侧的延迟相同,当滚动到顶部时,没有延迟 我希望有人能帮我:) 将类添加到css中: #header.fixed { position:fixed; top: 0 !important; /* important, to override inline style-tag */ } 向上滚动时将该类添加到菜单中,以便始终将其固定在页面顶部
将类添加到css中:
#header.fixed {
position:fixed;
top: 0 !important; /* important, to override inline style-tag */
}
向上滚动时将该类添加到菜单中,以便始终将其固定在页面顶部
var offset = 0;
function updateFloatingMenu(){
var scrollAmount = $(document).scrollTop();
if (scrollAmount > offset){
menu.stop().removeClass('fixed').animate({'top': scrollAmount}, speed);
} else {
menu.stop().addClass('fixed')
menu.css('top', scrollAmount); // Set top here so it's in the right place when reverting scroll
}
offset = scrollAmount; // Update current offset
}
var offset = 0;
function updateFloatingMenu(){
var scrollAmount = $(document).scrollTop();
if (scrollAmount > offset){
menu.stop().removeClass('fixed').animate({'top': scrollAmount}, speed);
} else {
menu.stop().addClass('fixed')
menu.css('top', scrollAmount); // Set top here so it's in the right place when reverting scroll
}
offset = scrollAmount; // Update current offset
}