滚动检测没有'调用新页面Javascript后无法工作

The scroll detection doesn't work after calling a new page Javascript

本文关键字:Javascript 新页面 工作 调用 检测 滚动      更新时间:2024-02-28

我正在使用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
}

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

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

特别感谢jQMtricks管理员Omar提供了这种检测

的好方法

尝试将==符号更改为:

// 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
}

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