scrollTop应用

$(window).scroll(function() {
var s =$(window).scrollTop();
console.log(s);
var h = document.documentElement.scrollHeight || document.body.scrollHeight;
console.log(h);
var scroll_length = document.body.clientHeight-document.body.scrollTop;
if (0<s&&s<50) {//导航条离页面顶部的距离(px)
//滑到底部
$(window).scrollTop(h);
}else if((h-scroll_length-50)<s&&s<h-scroll_length){
// 滑到顶部
$(window).scrollTop(-1);
}
});

posted @ 2018-10-18 23:25  金牛座的女孩  阅读(122)  评论(0编辑  收藏  举报