答案 0 :(得分:3)
scrollTop()
可以在这里帮到你。见the documentation
示例:
$('.scroll-up-button').on('click', function() {
var scrollIndex = $(window).scrollTop(); // current page position
$(window).scrollTop(y - 150); // scroll up 150px
}
$('.scroll-down-button').on('click', function() {
var scrollIndex = $(window).scrollTop(); // current page position
$(window).scrollTop(y + 150); // scroll down 150px
}
显然,这不是一个完整的解决方案,但应该帮助您开始正确的方向。
答案 1 :(得分:-1)
使用此fiddle
JS:
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
HTML:
<a href="#" class="scrollToTop">Scroll To Top</a>
CSS:
.scrollToTop{
width:100px;
height:130px;
padding:10px;
text-align:center;
background: whiteSmoke;
font-weight: bold;
color: #444;
text-decoration: none;
position:fixed;
top:75px;
right:40px;
display:none;
}
.scrollToTop:hover{
text-decoration:none;
}