js scroll 怎么滚到最下方

JavaScript020

js scroll 怎么滚到最下方,第1张

js判断window.scroll 判断滚动到底部的方法是设置一个变量,来检测鼠标位置。

具体的实现方法如下:

$(window).scroll(function() {

如果滚动的高度加上窗口的高度等于页面的高度就是到了底部

if($(window).scrollTop() + $(window).height() == $(document).height()) {

alert("bottom!")//已经滚动到底部

}

})

或者也可以写专用方法检测高度:

function getDocHeight() {

var D = document

return Math.max(

D.body.scrollHeight, D.documentElement.scrollHeight,

D.body.offsetHeight, D.documentElement.offsetHeight,

D.body.clientHeight, D.documentElement.clientHeight

)

}

然后再用以下方法检测:

$(window).scroll(function() {

if($(window).scrollTop() + $(window).height() == getDocHeight()) {

alert("bottom!")

}

})

1、zeptiojs(不支持IE)

http://zeptojs.com/

2、jGestures

http://jgestures.codeplex.com/

推荐博客文章: http://www.haorooms.com/post/jquery_jGestures

3、swiper

http://www.swiper.com.cn/

4、iScroll.js

http://cubiq.org/iscroll-5

http://iscrolljs.com/