zoukankan      html  css  js  c++  java
  • javascript移动设备触屏事件

    ontouchstart
    ontouchmove
    ontouchend
    ontouchcancel

    目前移动端浏览器均支持这4个触摸事件;

    /**
    * onTouchEvent
    */
    var div = document.getElementById("div");
    //touchstart类似mousedown
    div.ontouchstart = function(e){
    //事件的touches属性是一个数组,其中一个元素代表同一时刻的一个触控点,从而可以通过touches获取多点触控的每个触控点
    //由于我们只有一点触控,所以直接指向[0]
    var touch = e.touches[0];
    //获取当前触控点的坐标,等同于MouseEvent事件的clientX/clientY
    var x = touch.clientX;
    var y = touch.clientY;
    };
    //touchmove类似mousemove
    div.ontouchmove = function(e){
    //可为touchstart、touchmove事件加上preventDefault从而阻止触摸时浏览器的缩放、滚动条滚动等
    e.preventDefault();
    };
    //touchend类似mouseup
    div.ontouchup = function(e){
    //nothing to do
    };

  • 相关阅读:
    python-杂烩
    24 Python 对象进阶
    23 Python 面向对象
    22 Python 模块与包
    21 Python 异常处理
    20 Python 常用模块
    18 Python 模块引入
    2 Python 基本语法
    1 Python 环境搭建
    3 Python os 文件和目录
  • 原文地址:https://www.cnblogs.com/china-victory/p/3379613.html
Copyright © 2011-2022 走看看