捕获特定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