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

方法/步骤

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

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

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

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

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

  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. 当你触摸屏幕并抬起手指,只触发touchstart和touched。点击clear 可以清除本次测试的数据,可以再次测试。

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

  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开发,一般是通过eve ...

  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. css块级标签、行内标签、行内块级标签

    <html><head lang="en"> <meta charset="UTF-8"> <title>< ...

  2. listView上拉刷新下拉加载

    xlistview_header.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLa ...

  3. C#中Dictionary的用法

    在C#中,Dictionary提供快速的基于兼职的元素查找.他的结构是这样的:Dictionary<[key], [value]> ,当你有很多元素的时候可以使用它.它包含在System. ...

  4. Android开发之InstanceState详解(转)---利用其保存Activity状态

    Android开发之InstanceState详解   本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...

  5. [Java]读取文件方法大全(转)

    [Java]读取文件方法大全   1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile {     /**     ...

  6. iOS开发——GCDAsyncSocket

    新进的这家公司搞智能家居,就随便整理一下其相关技术吧!首先,从GCDAsyncSocket的使用问题着手. 正如名称一样GCDAsyncSocket开源类库是以苹果的GCD多任务处理机制完成的一个异步 ...

  7. 用apache配置多个tomcat webapp

    The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for m ...

  8. IFieldEdit Interface 接口

    Description The IFieldEdit interface is used when creating new fields. You should not use it to modi ...

  9. Ubuntu iptables 设置

    在ubuntu中由于不存在 /etc/init.d/iptales文件,所以无法使用service等命令来启动iptables,需要用modprobe命令. 启动iptables modprobe i ...

  10. Application Fundamentals

    Application Fundamentals 署名:译言biAji 链接:http://developer.android.com/guide/topics/fundamentals.html 应 ...