2013-11-28 3 views
5

특정 jQuery Mobile 페이지에서 스크롤 이벤트를 캡처하는 방법은 무엇입니까?특정 jQuery Mobile 페이지에서 스크롤 이벤트 캡처

페이지 pagebeforecreate에

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

, 동적으로 정렬되지 않은 목록 내에서 항목을로드

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

캡처 스크롤은

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

스크롤 이벤트입니다 잡히지 않아. 어떻게 캡처 할 수 있습니까?

'#pg_remote-address-book'대신 'window'를 입력하면 제대로 작동합니다. 하지만 특정 페이지에서 스크롤 이벤트를 캡처하고 싶습니다. 이걸 좀 도와 주실 수 있습니까?

+0

동적으로 생성 # pg_remote 주소 책인가? 그렇다면 다른 div에 이벤트를 버블 링하고 처리기를이 핸들에 연결해야합니다. –

+0

@ fos.alex, no, pg_remote-address-book은 동적으로 생성되지 않습니다. index.html에서 사용할 수 있습니다. – Malaiselvan

답변

2

이벤트를 바인드하려면 scrollstart 또는 scrollstop 이벤트를 청취하고 .on을 사용하십시오.

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

Demo