【发布时间】:2013-02-08 04:56:24
【问题描述】:
当用户向下滚动页面时,我想让一个 div 从右侧滑到我的页面上(该 div 将包含一个链接,可将它们带回页面顶部)。这是我目前正在使用的代码:
jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > 100) {
jQuery('.totop').animate({ right: '0px' });
} else {
jQuery('.totop').animate({ right: '-300px' });
}
});
还有 CSS:
.totop {
position:fixed;
bottom:50%;
right:-300px;
width:300px;
height:100px;
font-size:30px;
color:white;
background:#f18500;
}
Div 的行为非常奇怪,当我向下滚动 div 大约需要 5 秒钟才能出现,然后它出现在视图中,但看起来它正在尝试再次滑落,然后保持静止,当我滑回顶部它消失了……但大约 5 秒后又消失了。希望得到一些帮助以找出我的代码有什么问题。
【问题讨论】:
-
查看这篇文章以创建滚动到页面顶部:recentsolutions.net/web-development/smooth-scroll
标签: jquery html scroll jquery-animate