捕获特定jQuery Mobile页面上的滚动事件 [英] Capture scroll event on a particular jQuery Mobile Page

查看:70
本文介绍了捕获特定jQuery Mobile页面上的滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to capture the scroll event on a particular jQuery Mobile page?

页面

<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上,动态加载无序列表中的项目

On pagebeforecreate, dynamically loading items inside the unordered list

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

捕获滚动

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

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

The scroll event is not getting captured. How can I capture that?

如果我把'window'而不是'#pg_remote-address-book'那么它就可以了。但我想在特定页面上捕获滚动事件。你能帮我解决这个问题吗?

If I put 'window' instead of '#pg_remote-address-book' then it is working. But I want to capture the scroll event on a particular page. Can you please help me on this?

推荐答案

scrollstart scrollstop 事件,并使用 .on 来绑定事件。

Listen to scrollstart or scrollstop events, and use .on to bind events.

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




演示

Demo

这篇关于捕获特定jQuery Mobile页面上的滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆