当页面有滚动条时,显示滑到底部,点击对应按钮到底部
$('.scroll_bottom').click(function () {
$('html, body').animate({ scrollTop: $(document).height() }, 600)
})
到底部时,点击返回顶部
$('.scroll_top').click(function () {
$('html, body').animate({ scrollTop: '0px' }, 600)
})
滚动到顶部和底部之间时,显示滑到底部、返回顶部
$(window).bind('scroll', function () {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
scrollTop == 0
? $('.scroll_tip').show() && $('.scroll_top').hide('fast')
: $('.scroll_tip').hide() && $('.scroll_top').show('fast')
if (Math.round(scrollTop + windowHeight) == scrollHeight) {// 滚动到底部
$('.scroll_bottom').hide('fast')
} else {
$('.scroll_bottom').show('fast')
}
})
网友评论