我正在尝试使用jQuery Mobile,因为我无法在jQTouch中滑动一下页面.但是,对于jQuery Mobile而言,我不知道如何去执行滑动操作,而且如何使刷卡正确返回上一页.我一直在谷歌搜索和搜索文档,但找不到,所以我真的很感激一些帮助.
编辑:
我发现这个解决方案,谷歌有点多:
$('body').live('pagecreate',function (event) { $('div.ui-page').live("swipeleft",function () { var nextpage = $(this).next('div[data-role="page"]'); // swipe using id of next page if exists if (nextpage.length > 0) { $.mobile.changePage(nextpage,'slide'); } }); $('div.ui-page').live("swiperight",function () { var prevpage = $(this).prev('div[data-role="page"]'); // swipe using id of prevIoUs page if exists if (prevpage.length > 0) { $.mobile.changePage(prevpage,'slide',true); } // history.back(); // return false; }); });
这确实有效,但似乎并不稳定.当你滑动时,它会来回跳动.我还尝试了最后的注释掉的代码 – history.back(),这是在另一个网站上建议的.但这似乎更加不稳定,导致各种奇怪的跳跃.
解决方法
您可以使用jQuery .live“向左滑动”和“向右滑动”事件.
例:
$(document).ready(function() { $('.yourPage').live('swipeleft swiperight',function(event){ if (event.type == "swiperight") { var prev = $("#previndex",$.mobile.activePage); var previndex = $(prev).data("index"); if(previndex != '') { $.mobile.changePage({url:"index.PHP",type:"get",data:"index="+previndex},"slide",true); } } if (event.type == "swipeleft") { var next = $("#nextindex",$.mobile.activePage); var nextindex = $(next).data("index"); if(nextindex != '') { $.mobile.changePage({url:"index.PHP",data:"index="+nextindex}); } } event.preventDefault(); }); });
另外,这个YouTube视频也可以帮助您.
http://www.youtube.com/watch?v=Ij1RYI1p7rM
原文地址:https://www.jb51.cc/jquery/179251.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。