Javascript 一旦用户滚动到页面底部,向上滑动页脚-闪烁
我有以下代码:Javascript 一旦用户滚动到页面底部,向上滑动页脚-闪烁,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有以下代码: var footer = $('.footer'), extra = 0; // footer.css({ opacity: '0', display: 'block' }); $(window).scroll(function() { var scrolledLength = ( $(window).height() + extra ) + $(window).scrollTop(), documentHeight = $(document)
var footer = $('.footer'),
extra = 0;
// footer.css({ opacity: '0', display: 'block' });
$(window).scroll(function() {
var scrolledLength = ( $(window).height() + extra ) + $(window).scrollTop(),
documentHeight = $(document).height();
console.log( 'Scroll length: ' + scrolledLength + ' Document height: ' + documentHeight )
if( scrolledLength >= documentHeight ) {
footer
.addClass('bottom')
// .slideUp();
.stop().animate({ bottom: '0', opacity: '1' }, 300);
}
else if ( scrolledLength <= documentHeight && footer.hasClass('bottom') ) {
footer
.removeClass('bottom')
// .slideDown();
.stop().animate({ bottom: '-100', opacity: '0' }, 300);
}
});
var footer=$('.footer'),
额外=0;
//css({opacity:'0',display:'block'});
$(窗口)。滚动(函数(){
var scrolledLength=($(窗口).height()+额外)+$(窗口).scrollTop(),
documentHeight=$(document.height();
log('Scroll length:'+Scrolled length+'Document height:'+documentHeight)
如果(滚动长度>=文档高度){
页脚
.addClass(“底部”)
//.slideUp();
.stop().animate({bottom:'0',opacity:'1'},300);
}
否则,如果(scrolledLength您已经向页脚添加了一个类,则可以使用CSS处理动画:
.footer {
position: fixed;
width: 100%;
height: 100px;
bottom: -100px;
transition: all 200ms ease-out;
}
.footer.bottom {
bottom: 0;
}
更新:
显然,我在猜测页脚的样式,因为您没有提供CSS-当添加类.bottom
时,此代码将简单地为页脚设置动画。尝试使用CSS转换:
var footer=$('.footer'),
额外=0;
//css({opacity:'0',display:'block'});
$(窗口)。滚动(函数(){
var scrolledLength=($(窗口).height()+额外)+$(窗口).scrollTop(),
documentHeight=$(document.height();
如果(滚动长度>=文档高度){
页脚
.addClass(“打开”)
}
否则如果(如果页脚可见,scrolledLength存储一个布尔值,如果页脚可见,则将高度计算为documenth height-footerHeight?谢谢。它不会弹出,但它似乎只是停留在底部并向下移动,而不是像以前那样从“不知何处”出现。向上移动看起来不错,向下滑动消失!如果你可以发布link to you在JSFIDLE或Codepen上编写代码我可以做相关的更改。非常感谢。我不知何故无法让它在这个JSFIDLE中工作,但这是我迄今为止的代码:我将再看一眼,并尝试让它像在我的机器上一样工作,但以前从未使用过JSFIDLE,不确定会发生什么。我已经用一个工作链接更新了帖子ng fiddle。我强烈建议您仅在幻灯片动画中使用.footer
,然后将引导列和任何flexbox代码放在其中-这将使故障排除和使用代码更容易。