我希望能够在 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(..) 用于防止在页面转换期间绑定(bind)多个滑动事件。如果您有更多问题,请随时提问。
按钮解决方案:
工作示例也在这里: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;
});
});
关于javascript - 以编程方式滑回上一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15763903/