调用新页面Javascript后,滚动检测不起作用

时间:2015-02-22 14:26:05

标签: javascript jquery html5 jquery-mobile

我正在使用phonegap开发应用程序,除滚动检测外,一切正常!它工作正常,直到我使用jQueryMobile数据转换移动到另一个页面,之后它根本不起作用,尽管其他一切工作正常!

这是我用于滚动检测的代码

// to check if I reached the bottom of the slide
if($(window).scrollTop() + $(window).height() == $(document).height()) {
 // my code goes here
}
// to check if I'm at the top of the slide
if(document.body.scrollTop == 0 ) {
 // my code goes here
}

2 个答案:

答案 0 :(得分:1)

我找到了一个解决方案,我所做的只是按照这种方法来检测滚动,它运行得很好!

https://jqmtricks.wordpress.com/2014/07/15/infinite-scrolling/

特别感谢jQMtricks管理员 Omar 这种出色的检测方式

答案 1 :(得分:0)

尝试将==标志更改为:

// to check if I reached the bottom of the slide
if($(window).scrollTop() + $(window).height() >= $(document).height()) {
    // my code goes here
}
// to check if I'm at the top of the slide
if(document.body.scrollTop <= 0 ) {
    // my code goes here
}

有时,经过一些计算后,它们的值可能会低于或大于导致错误,因此在需要时使用<=>=是明智的。 不确定是否会有所帮助。