Javascript 页脚未在滚动底部设置高度动画
当我向下滚动50px到底部时,我希望页脚填满整个窗口。我试图给它的高度设置动画,但没有效果 HTML jqueryJavascript 页脚未在滚动底部设置高度动画,javascript,jquery,css,jquery-animate,Javascript,Jquery,Css,Jquery Animate,当我向下滚动50px到底部时,我希望页脚填满整个窗口。我试图给它的高度设置动画,但没有效果 HTML jquery $(window).scroll(function(){ var scrollTop = $(this).scrollTop(), docH = $(document).height(), winH = $(this).height(); if(scrollTop + winH >= docH-50){ $('footer').stop().anim
$(window).scroll(function(){
var scrollTop = $(this).scrollTop(),
docH = $(document).height(),
winH = $(this).height();
if(scrollTop + winH >= docH-50){
$('footer').stop().animate({height:'100%'},'slow');
}else{
$('footer').stop().animate({height:'50px'},'slow');
}
});
谢谢你问题是当你说高度时:“100%”就是说50像素的100% 尝试添加
footer { max-height: 100%; }
在css中
它应该能解决你的问题你能把你的代码放在小提琴上吗?你的意思是50像素在哪里?这是我在CSS中设置的50px吗?我认为jquery将其样式设置为样式属性,所以它否决了我在CSS中设置的样式?
$(window).scroll(function(){
var scrollTop = $(this).scrollTop(),
docH = $(document).height(),
winH = $(this).height();
if(scrollTop + winH >= docH-50){
$('footer').stop().animate({height:'100%'},'slow');
}else{
$('footer').stop().animate({height:'50px'},'slow');
}
});
footer { max-height: 100%; }