粘性标题 - 滚动 - CSS / jQuery
我希望创建一个粘性标题。每当用户向下滚动并且原始标题消失时,“粘性”标题就应该启动。
我目前使用这个:
$(function(){
// Check the initial Poistion of the Sticky Header
var stickyHeaderTop = $('#sticky').offset().top;
$(window).scroll(function(){
if( $(window).scrollTop() > stickyHeaderTop ) {
//$('#sticky').css({position: 'fixed', top: '0px', float: 'right'});
$('#sticky').addClass("sticky");
} else {
$('#sticky').removeClass("sticky");
}
});
});
尽管,当前的标题在用户刚刚滚动时添加“粘性”类,而不是在用户滚动时添加“粘性”类原来的标题应该消失了。
问候
I wish to create a sticky header. Everytime that the user scrolls down AND the original header goes away, then the "sticky" header should kick in.
I currently use this:
$(function(){
// Check the initial Poistion of the Sticky Header
var stickyHeaderTop = $('#sticky').offset().top;
$(window).scroll(function(){
if( $(window).scrollTop() > stickyHeaderTop ) {
//$('#sticky').css({position: 'fixed', top: '0px', float: 'right'});
$('#sticky').addClass("sticky");
} else {
$('#sticky').removeClass("sticky");
}
});
});
Although, the current one add the class "sticky" whenever a user just does a scroll, and not when the original header should be gone.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用带有
id="whateveryouwannacallit"
的div
包裹他并设置:
Wrap him with a
div
withid="whateveryouwannacallit"
and set:
事实上,你不需要包装。以下是
转到此页面的代码: http://viralpatel.net/博客/scroll-fix-header-jquery-facebook/
Actually, you won't need wrapping. Here is the code
Credit goes to this page: http://viralpatel.net/blogs/scroll-fix-header-jquery-facebook/