Javascript 在向上滚动时,如何重置scrollTop()div的位置?
我有一个固定的导航,我正在改变155px卷轴高度的徽标大小,并改变li的位置。一切正常,但当我向上滚动时,它不会重置。我是否需要为此创建一个大于函数?欢迎任何建议,谢谢:) 以下是jquery:Javascript 在向上滚动时,如何重置scrollTop()div的位置?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个固定的导航,我正在改变155px卷轴高度的徽标大小,并改变li的位置。一切正常,但当我向上滚动时,它不会重置。我是否需要为此创建一个大于函数?欢迎任何建议,谢谢:) 以下是jquery: $(document).scroll(function(){ if ($(this).scrollTop()>155){ $('.logo-nav').stop().animate({ height: 70 },20);
$(document).scroll(function(){
if ($(this).scrollTop()>155){
$('.logo-nav').stop().animate({ height: 70 },20);
} else {
$(".menu li").addClass("nav-scroll");
$('.logo-nav').stop().animate({ height: 145 },20);
}
});
以下是css:
li {
display: inline-block;
margin: 0;
position: relative;
top: 45px;
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
transition: all .4s ease;
}
.nav-scroll {
top: auto;
}
使用$(窗口)
而不是$(文档)
:
并确保将其包含在$(文档).ready()函数中。使用$(窗口)
而不是$(文档)
:
请确保将其放入$(document).ready()
函数中。我试过了,但它仍然没有重置,我是否遗漏了什么?@jgb你能给我们看一把工作的小提琴,这样我们就可以玩了吗?我试过了,但它仍然没有重置,我遗漏了什么吗?@jgb你能给我们看一把工作的小提琴,这样我们就可以玩了吗?
$(window).scroll(function() {
if ($(this).scrollTop() > 155){
$('.logo-nav').stop().animate({ height: 70 },20);
} else {
$(".menu li").addClass("nav-scroll");
$('.logo-nav').stop().animate({ height: 145 },20);
}
});