更新时间:2023-01-05 18:11:38
当用户滚动到特定位置时,
或者当他开始滚动时,您可以通过 jQuery 添加一个类.
When the user scolls to an specific position,
or in your case when he begins to scroll, you can add an class via jQuery.
在此处查看更多信息:
(代码取自链接中的帖子)
(Code is taken from the post in the link)
$(window).bind('scroll', function() {
if ($(window).scrollTop() > 50) {
$('.menu').addClass('fixed');
}
else {
$('.menu').removeClass('fixed');
}
});
当你用你的代码创建一个 fiddle 是***的,这样其他人就可以轻松修改你的代码和看看那里发生了什么..
it is the best when you create an fiddle with your code, so other people can easy modify your code and see whats going on there..