我希望能够在javascript函数(android/HTML5项目)内滑回上一页。我可以通过history.back()
回到上一页,但是,这段代码不会滑回去。
有可能让它也做滑动吗?
滑动解决方案
下面是一个工作示例:http://jsfiddle.net/Gajotres/ru3D3/
$(document).off('swipeleft').on('swipeleft', 'article', function(event){
var nextpage = $.mobile.activePage.next('article[data-role="page"]');
// swipe using id of next page if exists
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
}
});
$(document).off('swiperight').on('swiperight', 'article', function(event){
history.back();
return false;
event.handled = true;
});
此代码用于返回上一页:
history.back();
return false;
这一行:
$(document).off('swiperight').on('swiperight'
.off(..)用于防止在页面转换期间绑定多个滑动事件。如果你还有问题,请尽管问。
<标题>按钮解决方案:工作示例:http://jsfiddle.net/Gajotres/ru3D3/
$(document).on('pagebeforeshow', '[ data-role="page"]', function(){
$(document).off('click touchStart').on('click touchStart', '#slide-back-btn', function(){
history.back();
return false;
});
});
标题>