【发布时间】:2013-02-02 23:37:07
【问题描述】:
我有几个divs,但它们在语义上没有联系。因此我想拥有几组divs。
例子:
我希望能够在 {1,2,3,4,5} 之间左右滑动。其中一些页面有一个按钮,它应该打开(使用slideup 页面转换)子页面。例如,4 中的按钮将向上滑动页面 4.1。然后我希望能够在 4.1、4.2 和 4.3 之间再次左右滑动。
我的divs 看起来像这样:
<div data-role="page">
<div data-role="header">
<h2 class="ui-title">
<strong>Page 1</strong>
</h2>
</div>
<div data-role="content">
<strong>You are in page one.</strong>
</div>
</div>
<div data-role="page">
<div data-role="header">
<h2 class="ui-title">
<strong>Page 2</strong>
</h2>
</div>
<div data-role="content">
<strong>You are in page two.</strong>
<a href=#third data-transition="slideup">Go to page 3</a>
</div>
</div>
<div data-role="page" id="third">
<div data-role="header">
<h2 class="ui-title">Page three</h2>
</div>
<div data-role="content">
<strong>You are in page three.</strong>
</div>
</div>
使用以下 Javascript,我可以在 data-role="page" div 之间很好地左右滑动,但是,我无法区分子页面和主页面。我可以为主页面定义一个滑动(基本上使用我已经拥有的那个)然后为子页面定义另一个(也许通过使用ids 或其他东西来区分它们?)?
$(document).ready( function() {
$(document).on('swipeleft', 'div.ui-page', function () {
var nextpage = $(this).next('div[data-role="page"]');
if (nextpage.length >= 0) {
$.mobile.changePage(nextpage, {
transition: "slide",
reverse: false,
allowSamePageTransition: true
});
}
});
$(document).on('swiperight', 'div.ui-page', function () {
var prevpage = $(this).prev('div[data-role="page"]');
if (prevpage.length >= 0) {
$.mobile.changePage(prevpage, {
transition: "slide",
reverse: true,
allowSamePageTransition: true
});
}
});
});
【问题讨论】:
-
你能为此做一个小提琴吗??
-
@bipen 如果可以的话,我会的。否则我不会问,对吧?
-
我的意思是说只是一个小提琴..不是一个有效的小提琴或解决方案....我问的是这样我们就不必再重新创建整个事情了......我们可以拥有对你的 HTML 结构也有一些想法。我认为你在这里给出的 HTML 不是完整的 HTML
标签: jquery jquery-mobile swipe