Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture scroll event on a particular jQuery Mobile Page

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

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>

On pagebeforecreate, dynamically loading items inside the unordered list

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

Capture Scrolling

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

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

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?

like image 690
Malaiselvan Avatar asked Nov 01 '22 09:11

Malaiselvan


1 Answers

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

like image 200
Omar Avatar answered Nov 09 '22 23:11

Omar