javascript - 捕获特定 jQuery Mobile 页面上的滚动事件

标签 javascript jquery jquery-mobile

如何捕获特定 jQuery Mobile 页面上的滚动事件?

页面

<div id='pg_remote-address-book' data-role='page'>
  <div data-role='content' id='pg_remote-address-book_content'>
    <ul data-role='listview' id='ul_address_list'>
    </ul>
  </div>
</div>

在pagebeforecreate上,动态加载无序列表中的项目

for ( var i = 0; i < 100; i++ ) {
  $("#ul_address_list").append("<li>"+i+"</li>");
}

捕捉滚动

$('#pg_remote-address-book').scroll(function () {
  console.log('scrolled');
});

滚动事件未被捕获。我怎样才能捕捉到它?

如果我用“window”代替“#pg_remote-address-book”,那么它就可以工作了。但我想捕获特定页面上的滚动事件。你能帮我解决这个问题吗?

最佳答案

监听scrollstartscrollstop事件,使用.on绑定(bind)事件。

$(document).on("scrollstart", function (e) {
  var active = $.mobile.activePage[0].id;
  if (active == "pg_remote-address-book") {
    // Do something
  } else {
    // Do something else
  }
});

Demo

关于javascript - 捕获特定 jQuery Mobile 页面上的滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20275937/

相关文章:

jquery - 使用 phonegap/jquery for android 显示来自外部 url 的图像

javascript - Nativescript:逻辑控制sideDrawer

javascript - 我的 php 未在我的 Javascript 中解释

javascript - 以下函数中加号 (+) 的作用是什么,该函数摘自 jquery 源代码

jquery - 在 jQuery Mobile 中将参数传递给 page-id

jquery-mobile - jQuery Mobile, ListView 缩略图大小

javascript - 反引号中返回的 vue.js 计算方法未在模板中解析

javascript - 如何用短函数名声明一个 javascript 类并稍后分配给一个长类名?

javascript - Vue 发送参数值,声明要发送的参数

javascript - IOS 11.1 SecurityError (DOM Exception 18) : Blocked attempt to use history. replaceState() 更改 session 历史URL