admin 发表于 2013-8-8 19:06:24

Jquery Mobile 触摸事件(touch)

    在 jQuery Mobile 中有一些触摸事件是可定制的。然而,这些事件仅当与支持触摸功能的设备进行交互的用户访问您的 jQuery Mobile 网站时才可用。当这些事件可用时,您可以触发任何自定义java script 作为对五种不同的事件的响应tap、taphold、swipe、swipeleft 和 swiperight。

    tap(轻击):一次快速完整的轻击后触发
    taphold(轻击不放):轻击并不放(大约一秒)后触发
    swipe(滑动):一秒内水平拖拽大于30PX,或者纵向拖曳小于20px的事件发生时触发的事件。多长时间拖拽多少px可以设置的。这个事件有其相关联的属性,分别为

    scrollSupressionThreshold (默认: 10px) – 水平方向拖拽大于这个值,将不触发。
    durationThreshold (默认: 1000ms) – 滑动时间超过这个数值就不会产生滑动事件。
    horizontalDistanceThreshold (默认: 30px) – 水平划动距离超过这个数值才会产生滑动事件。
    verticalDistanceThreshold (默认: 75px) – 竖直划动距离小于这个数值才会产生滑动事件。

    swipeleft(左划):划动事件为向左的方向时触发
    swiperight(右划):划动事件为向右的方向时触发


<!DOCTYPE HTML>
    <html>
    <head>
      <title>Understanding the jQuery Mobile API</title>
      <link rel="stylesheet" href="jquery.mobile.css" />
      <script src="jquery.js"></script>
      <script type="text/java script">
      $(document).ready(function(){
          $(".tap-hold-test").bind("taphold", function(event) {
            $(this).html("Tapped and held");
          });
      });
      </script>
      <script src="jquery.mobile.js"></script>
    </head>

    <body>
      <div data-role="page" id="my-page">
      <div data-role="header">
                <h1>Header</h1>
            </div>
            <div data-role="content">
                <ul data-role="listview" id="my-list">
                  <li class="tap-hold-test">Tap and hold test</li>
                </ul>
      </div>
      </div>
    </body>
    </html>
   

    要绑定这些事件,只需要在document.ready()中进行编程即可,如下代码示例:


从上面的代码可以看到,将一个list列表跟taphold事件进行了绑定,当DOM加载完毕后,当触发taphold事件后,就会显示Tapped and held的提示信息。


小雪 发表于 2013-9-27 16:05:59

我抢、我抢、我抢沙发~

小雪 发表于 2013-10-1 13:11:59

没看完~~~~~~ 先顶,好同志

uqobk8216 发表于 2013-10-4 01:24:27

有竞争才有进步嘛

phonegap100 发表于 2013-10-5 15:51:24

非常感谢楼主。。。

phonegap100 发表于 2013-10-7 06:04:09

有竞争才有进步嘛

小雪 发表于 2013-10-8 22:17:57

非常感谢楼主。。。

markt 发表于 2015-1-12 16:57:55

"taphold"与安卓手机上的长按事件冲突怎么解决
页: [1]
查看完整版本: Jquery Mobile 触摸事件(touch)