我有这个返回顶部按钮的解决方案。
HTML:
<div id='toTop'>To The Top!</div><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
CSS:
#toTop {
padding: 5px 3px;
background: #000;
color: #fff;
position: fixed;
bottom: 0;
right: 5px;
display: none;
}
JS:
$(window).scroll(function() {
if ($(this).scrollTop()) {
$('#toTop').fadeIn();
} else {
$('#toTop').fadeOut();
}
});
http://jsfiddle.net/robert/fjXSq/
它起作用了。但是ı想要当滚动到底部200px时,让滚动按钮给我。我如何设置这个选项?
试试这个代码:
$(window).scroll(function() {
if ($(this).scrollTop() > ($('html').height() - $(window).height() - 200)) {
$('#toTop').fadeIn();
} else {
$('#toTop').fadeOut();
}
});