我试着让scroll上的导航粘性,而不是在这么小的东西上使用笨重的插件。
下面是到目前为止的代码:
var menuOffset = $('#nav-wrap')[0].offsetTop;
$(document).bind('ready scroll', function() {
var docScroll = $(document).scrollTop();
if (docScroll > 300) {
if (!$('#nav-wrap').hasClass('sticky')) {
$('#nav-wrap').addClass('sticky').css({
top: '-80px'
}).stop().animate({
top: 0
}, 500);
}
} else {
$('#nav-wrap').removeClass('sticky').removeAttr('style');
}
});虽然我需要在移除类'sticky‘和静态导航回到原位(以及在浏览器视窗中)之前,我需要#nav-wrap向上滑动,因为我不喜欢它跳回原位。有什么建议吗?
http://jsfiddle.net/D8V7b/60/
谢谢
发布于 2014-04-02 23:57:37
我假设在您的真实场景中,您不能仅仅使用css位置固定来实现这一点。
看起来你等待激活粘性的时间太长了,试着让它在文档的scrollTop只有20的时候生效,例如,而不是你的代码中的300。
var docScroll = $(document).scrollTop();
if (docScroll > 20) { ...更新的fiddle:http://jsfiddle.net/JvnwY/
https://stackoverflow.com/questions/22816217
复制相似问题