处理Touch事件能让你了解到用户的每一根手指的位置,在touch事件触发的时候产生,可以通过touch event handler的event对象取到,如果基于zepto.js开发,一般是通过event.touches[0]来获取属性。重要属性如下:clientX,clientY:触摸点相对于浏览器窗口viewport的位置;pageX,pageY: 触摸点相对于页面的位置;screenX,screenY:触摸点相对于屏幕的位置 ;identifier:touch对象的unique ID

方法/步骤

  1. 1

    你可以绑定以下四种Touch事件来了解基本的touch事件:

    touchstart:手指触摸屏幕上的时候触发

    touchmove:手指在屏幕上移动的时候触发

    touchend:手指从屏幕上拿起的时候触发

    touchcancel:系统取消touch事件的时候触发

  2. 2

    html:

    <div id="touch_test">

    <span class="clear">clear</span>

    <ul id="touchs">

    </ul>

    </div>

    css:

    #touchs{

    margin: 10px;width: 100px;height: auto;min-height: 100px;

    border:1px solid #c2ddb6;border-radius: 2px;background: #c2ddb6;

    }

    #touchs li {list-style: none;}

    .clear{

    margin-left: 10px;display:inline-block;height: 24px;width: 40px;color:#fff;

    font-size: 14px;line-height: 24px;background: #c2ddb6;text-align: center;

    }

    js:

    <script type="text/javascript" src="script/zepto.min.js"></script>

    <script type="text/javascript">

    ;(function($){

    $('#touchs').find('li').remove();

    $('#touchs').bind("touchstart",function(event){

    var touchpros =event.touches[0];

    console.log(touchpros);

    $('#touchs').append('<li>touchstart...</li>');

    });

    $('#touchs').bind("touchmove",function(){

    $('#touchs').append('<li>touchmove...</li>');

    });

    $('#touchs').bind("touchend",function(){

    $('#touchs').append('<li>touchend...</li>');

    });

    $('#touchs').bind("touchcancel",function(){

    $('#touchs').append('<li>touchcancel...</li>');

    });

    $('.clear').bind("click",function(){

    $('#touchs').find('li').remove();

    });

    })(Zepto);

    </script>

  3. 3

    当你触摸屏幕并抬起手指,只触发touchstart和touched。点击clear 可以清除本次测试的数据,可以再次测试。

     
  4. 4

    当如果手指触摸屏幕并移动后抬起会触发touchstart,多次touchmove,touchend或touchcanel

     
  5. 5

    可以根据基本的touch事件来封装成你想要实现复杂的效果,比如向左或向右滑动,

    向上或向下滑动,并在滑动时封装你想实现的效果。

    打开:https://github.com/madrobby/zepto/tree/master/src;

    touch.js封装好了滑动事件的处理,将其添加到自己的项目中,就可以直接调用向右、右、上、下滑动的事件。这样zepto.js官网手册中的例子就可以正常运行了。

     

zepto.js 处理Touch事件(实例)的更多相关文章

  1. zepto.js 处理Touch事件

    处 理Touch事件能让你了解到用户的每一根手指的位置,在touch事件触发的时候产生,可以通过touch event handler的event对象取到,如果基于zepto.js开发,一般是通过ev ...

  2. js的touch事件的实际引用

    一开始做前端页面的时候,接触的也是js,但是随后便被简单高效的jquery吸引过去,并一直使用至今. 而js,则被我主观的认为底层技术而抛弃. 直到这几天工作需要,研究移动端页面的触屏滑动事件,搜索j ...

  3. js的Touch事件

    js的touch事件,一般用于移动端的触屏滑动$(function(){document.addEventListener("touchmove", _touch, false); ...

  4. Zepto.js库touch模块代码解析

    Zepto.js也许并不陌生,专门针对移动端开发,Zepto有一些基本的触摸事件可以用来做触摸屏交互(tap事件.swipe事件),Zepto是不支持IE浏览器的. 下面来解析一些Zepto.js触摸 ...

  5. 怎么使用zepto.js的tap事件引起的探索

    前言:   在使用zepto.js之前,你首先要知道它是什么?为什么要使用它?以及它和jquery有什么区别? ①:简单来说zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与j ...

  6. zepto.js的touch模块

     touch库实现了什么和引入背景 touch模块是基于zepto.js的. click事件在移动端上会有 300ms 的延迟,同时因为需要 长按 , 双触击 等富交互,所以我们通常都会引入类似 ze ...

  7. JS的Touch事件们,触屏时的js事件

    丫的,终于找到了JS在平板电脑上的事件!!!   iphone.ipod Touch.ipad触屏时的js事件   1.Touch事件简介   pc上的web页面鼠标会产生onmousedown.on ...

  8. zepto.js 的tap事件中点击一次触发两次事件

    html代码: <div class="xh-lxx-cart-count1"> <span class="minus">-</s ...

  9. JS模拟Touch事件

    var ele = document.getElementsByClassName('target_node_class')[0] //may have x and y properties in s ...

随机推荐

  1. activity之栈管理

    在android中.一个activity组件能够激活还有一个activity组件:本程序activity和其他程序的activity.     若新的被激活的activity组件属于还有一个应用程序, ...

  2. JQ 模仿注册时等待的时间

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. hdu2429Ping pong

    Problem Description N(3<=N<=20000) ping pong players live along a west-east street(consider th ...

  4. Spring-----8、深入理解容器中的bean

    转载自:http://blog.csdn.net/hekewangzi/article/details/45648687

  5. Struts2 实战经验 之 入门

    Struts2以WebWork为核心,采用拦截器机制处理用户请求,这样的设计使业务逻辑控制器能够与Servlet API完全脱离开,降低了藕联性. Part 1. 安装与配置 下载struts-2.3 ...

  6. 【Python备忘】python判断文件和文件夹是否存在

    python判断文件和文件夹是否存在 import os os.path.isfile('test.txt') #如果不存在就返回False os.path.exists(directory) #如果 ...

  7. linux shell--算术运算

    求和: 方法一.使用命令替换法: #!/bin/bash read -p 'input number a...' numA read -p 'input number b...' numB #这里有两 ...

  8. SQL Server 日志文件增长原因定位

    方法 1.sys.databases; -------------------------------------------------------------------------------- ...

  9. Oracle ORA-01555(快照过旧)

    一.引言: [oracle@yft yft]$ oerr ora 01555 01555, 00000, "snapshot too old: rollback segment number ...

  10. Oracle EBS-SQL (CST-2):检查有BOM但成本不基于累积的数据.sql

    select c.segment1                                                                          物料编码,     ...