我看过几种制作持久头的jQuery方法,但是我真的不明白函数是如何工作的。
我的想法是,在页面的某个地方有一个下拉菜单,当屏幕的顶部到达它的位置时,将下拉菜单更改为顶部的固定位置。
任何帮助都将不胜感激。
发布于 2013-09-24 17:04:53
像这样吗?
HTML
<div class="test">Hello!</div>jQuery
$( window ).scroll(function() {
offset = $('.test').offset();
if ( offset.top < $( window ).scrollTop() + 10 ){
$('.test').addClass('fixed');
}
});CSS
body{
height: 2000px;
}
.test{
position: relative;
top: 100px;
}
.test.fixed{
position: fixed;
top: 10px;
}https://stackoverflow.com/questions/18987470
复制相似问题