2011-12-22 79 views
3

我正在jquery移動項目上工作。我有兩個HTML頁面。從index.html我有一個swipeleft事件page.html,它工作正常。從page.html我想swiperight,所以我回到index.html但這不會工作。如何使用jquery mobile從一個html頁面滑回另一個頁面

如果我在單個文檔內部的內部頁面之間滑動,而不是在html頁面之間滑動,代碼工作正常。我需要使用幾個HTML頁面。

有沒有人得到這個工作?將不勝感激的答案。

在我的index.html頁面這我我刷卡代碼:

<script> 
$(document).ready(function() { 

$("#main").bind('swipeleft',function(event, ui){ 
     $.mobile.changePage("page.html", "slide"); 
}) 

}) 
</script> 

這是我爲我的page.html中的代碼:

<script> 
$(document).ready(function() { 

$("#main").bind('swiperight',function(event, ui){ 
     $.mobile.changePage("index.html", "slide"); 
}) 

}) 
</script> 

回答

0

你不應該使用$。就緒() ,您應該使用pageInit()
此外,請確保您網頁上的所有ID在所有網頁中都是唯一的,而不僅僅是網頁的唯一ID。

0

我在所有頁面上使用下面的代碼進行導航,在所有頁面上滑動它的工作正常,但他們沒有滑動動畫。

$("#main").bind('swipeleft',function(event, ui){ 
     goPage1(); 
}) 
$("#main").bind('swiperight',function(event, ui){ 
     goPage2(); 
}) 

function goPage1(){ 
    var dirPath = dirname(location.href); 
    var fullPath = dirPath + "/page1.html"; 
    window.location=fullPath; 
} 

function goPage2(){ 
    var dirPath = dirname(location.href); 
    var fullPath = dirPath + "/page2.html"; 
    window.location=fullPath; 
} 
function dirname(path){ 
    return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); 
} 
相關問題