JQuery mobile滑動觸發打開面板

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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章