jQuery Mobile - binding to pageinit event

做~自己de王妃 提交于 2019-12-28 06:46:10

问题


I am trying to understand the following jQuery Mobile example.

$( '#aboutPage' ).live( 'pageinit',function(event){
  alert( 'This page was just enhanced by jQuery Mobile!' );
});

What is #aboutPage in this context? What is the object pageinit is binding to?


回答1:


aboutPage should be the id of the page.(i.e.div with data-role="page").live() attaches the funcion you have defined which contains thealert to the pageinit event of aboutPage.pageinit is triggered on a page when the page is initialized.

So in short What your code does is

it will execute the alert statement when aboutPage is initialized

The page might be initialized even if it is not in view.So even before you go to that page,the pageinit of the div will be triggered.If you are loading another html file as the new page pageinit for that page will be triggered only when you load that page into view.So,in your case if you want to do something when your div comes into view,you can try the pagebeforeshow and pageshow.pagebeforeshow will be triggered on the new page before animation starts and pageshow after animation is over.



来源:https://stackoverflow.com/questions/7729729/jquery-mobile-binding-to-pageinit-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!