下面是我的密码。我不知道哪里出了问题。
JavaScript:
(function () {
$(window).scroll(function(){
var scrollTop=Math.round($('.nav').offset().top);
if (scrollTop > 1000 ) {
$('.nav').animate({top:0});
}
if (scrollTop < 1000) {
$('.nav').animate({top:90});
}
});
}());
HTML:
<div class="nav"></div>
<div style="display:block; height:16000px; border:1px solid #000;" id="wrp"></div>
JSFIDDLE
发布于 2014-03-31 07:48:44
查看jsfiddle.net/sjnilan/JLduB中的演示
$(window).scroll(function(){
var scrollTop=Math.round($('.nav').offset().top);
if (scrollTop > 100 ) {
$('.nav').stop().animate({top:0});
}
if (scrollTop < 100) {
$('.nav').stop().animate({top:90});
}
});
发布于 2014-03-31 08:08:32
要使用top
,必须将position:relative/absolute/fixed
设置为元素.nav
,具体取决于您想要的内容。
https://stackoverflow.com/questions/22755941
复制相似问题