我的應用程序有兩個面板作爲主佈局,所以所有的子頁面都有這兩個面板。現在,我想爲應用程序中的所有頁面註冊滑動事件,以便用戶可以從任何地方訪問這兩個面板。 我創造了這個功能,在這裏,這樣我就可以把這種來自不同的地方進行註冊:如何在JQM應用程序的所有頁面上註冊刷卡事件?
function registerSwipeEvents() {
//panel swipe from left and right for categories, favs.
$(document).on("swipeleft swiperight", '[data-role=page]', function (e) {
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel.
// We do this by checking the data that the framework stores on the page element (panel: open).
if ($.mobile.activePage.jqmData("panel") !== "open") {
if (e.type === "swipeleft") {
$(".right-panel").panel("open");
} else if (e.type === "swiperight") {
$(".left-panel").panel("open");
}
}
});
}
我已經打過電話,從pageinit此功能(運行腳本只有一次),pagebeforeshow和pageshow(始終運行),如這個:
$('#HomePage').on('pageshow', function() {
getFavouritesFromClient();
});
但是這個事件不適用於所有頁面,當我第二次從一個頁面轉到另一個頁面時!也許我沒有正確地使用這些事件,但是迄今爲止第一輪導航工作的最好的一個是pageshow。
你使用的是單文件還是多文件? – Omar
@Omar多個文件,但主頁ID是我的主'[data-role = page]'的主要ID,並且所有進入的內容都被注入到內容中。 –
'$(document).on('pageshow','#HomePage',function(){'將會訣竅。另外,通過這個答案,這很有幫助http://stackoverflow.com/a/15806954/1771795 – Omar