JQuery mobile滑動觸發打開面板
阿新 • • 發佈:2018-11-13
JQuery Mobile簡單實現螢幕向右滑動實現彈出面板
效果圖
核心程式碼
<script>
$(document).on("pagecreate","#pageone",function(){ //功能載入
$("p").on("swipe",function(){ //選擇P標籤監聽滑動事件
//$("swiperight").text("滑動檢測!"); //一旦滑動就開啟a標籤
$('a').click();
});
});
</script>
<!--也可以這樣寫-- >
<script>
$(document).ready(function(){
$("p").on("swiperight",function(){
//$("span").text("滑動檢測!");
$('a').click();
});
});
</script>
完整演示程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content= "width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js" ></script>
<script>
$(document).on("pagecreate","#pageone",function(){
$("p").on("swiperight",function(){
//$("span").text("滑動檢測!");
$('a').click();
});
});
</script>
</head>
<body>
<div data-role="page" id="pageone">
<div data-role="panel" id="myPanel">
<h2>面板頭部</h2>
<p>你可以通過點選面板外部區域或按下 Esc 鍵或滑動來關閉面板。</p>
</div>
<div data-role="header">
<h1>swipe 事件</h1>
</div>
<div data-role="main" class="ui-content">
<p>在下面的文字或方框上滑動。</p>
<p style="border:1px solid black;height:200px;width:200px;"></p>
<a href="#myPanel"></a>
</div>
<div data-role="footer">
<h1>頁尾文字</h1>
</div>
</div>
</body>
</html>