觸摸事件在用戶觸摸屏幕(頁(yè)面)時(shí)觸發(fā)。

lamp 觸摸事件同樣可應(yīng)用與桌面電腦上:點(diǎn)擊或者滑動(dòng)鼠標(biāo)!


jQuery Mobile 點(diǎn)擊

點(diǎn)擊事件在用戶點(diǎn)擊元素時(shí)觸發(fā)。

如下實(shí)例:當(dāng)點(diǎn)擊 <p> 元素時(shí),隱藏當(dāng)前的 <p> 元素:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("tap",function(){
    $(this).hide();
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>tap 事件</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p>敲擊我,我會(huì)消失。</p>
    <p>敲擊我,我會(huì)消失。</p>
    <p>敲擊我,我也會(huì)消失。</p>
  </div>

  <div data-role="footer">
    <h1>頁(yè)腳文本</h1>
  </div>
</div> 

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


jQuery Mobile 點(diǎn)擊不放(長(zhǎng)按)

點(diǎn)擊不放(長(zhǎng)按) 事件在點(diǎn)擊并不放(大約一秒)后觸發(fā)

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("taphold",function(){
    $(this).hide();
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>taphold 事件</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p>如果您敲擊并保持一秒鐘,我會(huì)消失。</p>
    <p>敲擊并保持住,我會(huì)消失。</p>
    <p>敲擊并保持住,我也會(huì)消失。</p>
  </div>

  <div data-role="footer">
    <h1>頁(yè)腳文本</h1>
  </div>
</div> 

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


jQuery Mobile 滑動(dòng)

滑動(dòng)事件是在用戶一秒內(nèi)水平拖拽大于30PX,或者縱向拖曳小于20px的事件發(fā)生時(shí)觸發(fā)的事件:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("swipe",function(){
    $("span").text("滑動(dòng)檢測(cè)!");
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>swipe 事件</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p>在下面的文本或方框上滑動(dòng)。</p>
    <p style="border:1px solid black;height:200px;width:200px;"></p>
    <p><span style="color:red"></span></p>
  </div>

  <div data-role="footer">
    <h1>頁(yè)腳文本</h1>
  </div>
</div> 

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例



jQuery Mobile 向左滑動(dòng)

向左滑動(dòng)事件在用戶向左拖動(dòng)元素大于30px時(shí)觸發(fā):

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("swipeleft",function(){
    alert("您向左滑動(dòng)!");
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>swipeleft 事件</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p style="border:1px solid black;margin:5px;">向左滑動(dòng) - 不要超出邊框!</p>
  </div>

  <div data-role="footer">
    <h1>頁(yè)腳文本</h1>
  </div>
</div> 

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


jQuery Mobile 向右滑動(dòng)

向右滑動(dòng)事件在用戶向右拖動(dòng)元素大于30px時(shí)觸發(fā):

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://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(){
    alert("向右滑動(dòng)!");
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>swiperight 事件</h1>
  </div>

  <div data-role="main" class="ui-content">
    <p style="border:1px solid black;margin:5px;">向右滑動(dòng) - 不要超出邊框!</p>  
  </div>

  <div data-role="footer">
    <h1>頁(yè)腳文本</h1>
  </div>
</div> 

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例