2012-08-02 87 views
1

jQuery的功能(在其自己的作品):如何使用jQuery函数创建jQuery Mobile页面幻灯片?

$("#firstpage").live('pageinit', function (evt) { 
    $("#firstpage").bind("swipeleft", function (e) { 
     alert ("you swiped left!"); 
    }); 
}); 

jQuery Mobile的链接(也适用于自己的):

<a href="#secondpage" data-transition="slide">GO TO PAGE 2</a> 

那么,如何将二者结合起来?谢谢!

回答

1

检查jQuery Mobile的文档
http://jquerymobile.com/demos/1.1.1/docs/api/methods.html

$("#firstpage").live('pageinit', function (evt) { 
    $("#firstpage").bind("swipeleft", function (e) { 
     $.mobile.changePage("#secondpage", { transition : 'slide'}); 
    }); 
}); 
+0

谢谢,这就是我一直在寻找。由于显而易见的原因,它不如原生应用程序那么敏捷,但仍然有用。 – orbwhacker 2012-08-03 15:57:09

+0

@orbwhacker如果你想响应,你可以实现它,但你必须使用'touchstart' /'touchmove' /'touchend'。退房swipejs.com,这是一些漂亮的代码。 jQuery Mobile事件“swipeleft”/“swiperight”只是没有响应。 – Jasper 2012-08-04 16:34:26

2

您可以使用$.mobile.changePage(),这是内部用于页面之间转换的内容。这里有一个例子:

$(document).delegate("#firstpage", 'pageinit', function (evt) { 
    $(this).bind("swipeleft", function (e) { 
     $.mobile.changePage("#secondpage", { 
      transition : 'slide' 
     }); 
    }); 
}).delegate("#secondpage", 'pageinit', function (evt) { 
    $(this).bind("swiperight", function (e) { 
     $.mobile.changePage("#firstpage", { 
      transition : 'slide', 
      reverse : true 
     }); 
    }); 
});​ 

这里是一个演示:http://jsfiddle.net/QjUMh/

退房的文档$.mobile.changePage,看看它拥有的所有选项:您可以使用$.mobile.changePage()方法做http://jquerymobile.com/demos/1.1.1/docs/api/methods.html