zoukankan      html  css  js  c++  java
  • 移动设备比较好事件处理方式

    event.changedTouches[0]:

    如果是jquery的event对象,使用event.originalEvent.changedTouches[0]

    function touchHandler(event)
    {
     var touches = event.changedTouches,
        first = touches[0],
        type = "";
     
         switch(event.type)
    {
        case "touchstart": type = "mousedown"; break;
        case "touchmove":  type="mousemove"; break;         
        case "touchend":   type="mouseup"; break;
        default: return;
    }
    var simulatedEvent = document.createEvent("MouseEvent");
    simulatedEvent.initMouseEvent(type, true, true, window, 1,
                              first.screenX, first.screenY,
                              first.clientX, first.clientY, false,
                              false, false, false, 0/*left*/, null);
     
    first.target.dispatchEvent(simulatedEvent);
    event.preventDefault();
    }
     
    function init()
    {
       document.addEventListener("touchstart", touchHandler, true);
       document.addEventListener("touchmove", touchHandler, true);
       document.addEventListener("touchend", touchHandler, true);
       document.addEventListener("touchcancel", touchHandler, true);     
    }

  • 相关阅读:
    scss的初级学习随笔小计
    trimpash实现jd选项卡首次输入
    透明度动画
    js原生动画一匀速动画
    filter滤镜的使用
    scss实现不同方向的三角
    模板方法模式-考题抄错,会做也白搭
    设计模式概述
    mysql数据库
    夜饮东坡醒复醉
  • 原文地址:https://www.cnblogs.com/gaoxue/p/2501749.html
Copyright © 2011-2022 走看看