我在单个页面中创建了多个 div 滑动,以便页面保持不变但 div 被更改。使用 jquery 移动页面滑动的帮助并进行了一些自定义。div 滑动工作完全正常,但我创建了一个面板,每当我从第一个 div 转到第二个 div 并再次回到第一个 div 时,面板不起作用。请帮我处理面板。这是我的代码:-
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="jquery/jquery.mobile-1.4.5.min.css" />
<link rel="stylesheet" href="css/style.css" />
<script src="jquery/jquery.min.js"></script>
<script src="js/swipe-page.js"></script>
<script src="jquery/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div id="header" data-role="header" data-id="header" data-position="fixed" data-tap-toggle="false">
<h1>Swipe left or right</h1>
<a href="#mypanel" data-icon="bars" data-iconpos="notext" data-shadow="false" data-iconshadow="false" class="ui-nodisc-icon">Open left panel</a>
<!-- <div data-role="navbar">
<ul>
<li><a href="index.html" data-icon="grid" class="ui-btn-active">News</a></li>
<li><a href="market.html" data-icon="star">Market</a></li>
<li><a href="#" data-icon="gear">Announcement</a></li>
<li><a href="#" data-icon="comment">Portfolio</a></li>
</ul>
</div> --><!-- /navbar -->
</div><!-- /header -->
<div data-role="page" id="index" class="demo-page" data-title="Index" data-dom-cache="true" data-theme="a" data-next="market">
<div role="main" class="ui-content">
<h1>Div 1</h1>
</div><!-- /content -->
<div data-role="panel" id="mypanel" data-theme="a" data-display="overlay" data-position="left" >
<ul data-role="listview">
<li data-icon="delete"><a href="#" data-rel="close">Close menu</a></li>
<li><a href="#panel-fixed-page2">Accordion</a></li>
<li><a href="#panel-fixed-page2">Ajax Navigation</a></li>
<li><a href="#panel-fixed-page2">Autocomplete</a></li>
<li><a href="#panel-fixed-page2">Buttons</a></li>
<li><a href="#panel-fixed-page2">Checkboxes</a></li>
<li><a href="#panel-fixed-page2">Collapsibles</a></li>
<li><a href="#panel-fixed-page2">Controlgroup</a></li>
</ul>
</div><!-- /panel -->
</div><!-- /page -->
<div data-role="page" id="market" class="demo-page" data-title="Market" data-dom-cache="true" data-theme="a" data-prev="index">
<div role="main" class="ui-content">
<h1>Div 2</h1>
</div><!-- /content -->
<div data-role="panel" id="mypanel" data-theme="a" data-display="overlay" data-position="left">
<ul data-role="listview">
<li data-icon="delete"><a href="#" data-rel="close">Close menu</a></li>
<li><a href="#panel-fixed-page2">Accordion</a></li>
<li><a href="#panel-fixed-page2">Ajax Navigation</a></li>
<li><a href="#panel-fixed-page2">Autocomplete</a></li>
<li><a href="#panel-fixed-page2">Buttons</a></li>
<li><a href="#panel-fixed-page2">Checkboxes</a></li>
<li><a href="#panel-fixed-page2">Collapsibles</a></li>
<li><a href="#panel-fixed-page2">Controlgroup</a></li>
</ul>
</div><!-- /panel -->
</div><!-- /page -->
<div id="footer" data-id="footer" data-position="fixed" data-tap-toggle="false">
<div data-role="navbar">
<ul>
<li><a href="#">Latest News</a></li>
<li><a href="#">Featured News</a></li>
<li><a href="#">Most Read</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</body>
</html>
用于 div 滑动的 javascript 是:-
$(document).on('pageinit', function(event){
$('div.ui-page').on("swipeleft", function () {
var nextpage = $(this).next('div[data-role="page"]');
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, "slide", false, true);
}
});
$('div.ui-page').on("swiperight", function () {
var prevpage = $(this).prev('div[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, { transition: "slide", reverse: true }, true, true);
}
});
});