一、手机上的触摸事件

基本事件:

touchstart   //手指刚接触屏幕时触发

touchmove    //手指在屏幕上移动时触发

touchend     //手指从屏幕上移开时触发

下面这个比较少用:

touchcancel  //触摸过程被系统取消时触发

每个事件都有以下列表,比如touchend的targetTouches当然是 0 咯:

touches         //位于屏幕上的所有手指的列表

targetTouches   //位于该元素上的所有手指的列表

changedTouches  //涉及当前事件的所有手指的列表

每个事件有列表,每个列表还有以下属性:

复制代码

其中坐标常用pageX,pageY:

pageX    //相对于页面的 X 坐标

pageY    //相对于页面的 Y 坐标

clientX  //相对于视区的 X 坐标

clientY  //相对于视区的 Y 坐标

screenX  //相对于屏幕的 X 坐标

screenY  //相对于屏幕的 Y 坐标

identifier // 当前触摸点的惟一编号

target   //手指所触摸的 DOM 元素

其他相关事件:

event.preventDefault()   //阻止触摸时浏览器的缩放、滚动条滚动

var supportTouch = "createTouch" in document  //判断是否支持触摸事件

更多深入内容?点击:http://www.cesclub.com/bw/jishuzhongxin/Webjishu/2011/1216/18069.html

二、示例

以下是获取不同类型滑动的代码具体做法,结合前人的思想,封装好了,可以借鉴学习:

 var touchFunc = function(obj,type,func) {
//滑动范围在5x5内则做点击处理,s是开始,e是结束
var init = {x:,y:,sx:,sy:,ex:,ey:};
var sTime = , eTime = ;
type = type.toLowerCase(); obj.addEventListener("touchstart",function(){
sTime = new Date().getTime();
init.sx = event.targetTouches[].pageX;
init.sy = event.targetTouches[].pageY;
init.ex = init.sx;
init.ey = init.sy;
if(type.indexOf("start") != -) func();
}, false); obj.addEventListener("touchmove",function() {
event.preventDefault();//阻止触摸时浏览器的缩放、滚动条滚动
init.ex = event.targetTouches[].pageX;
init.ey = event.targetTouches[].pageY;
if(type.indexOf("move")!=-) func();
}, false); obj.addEventListener("touchend",function() {
var changeX = init.sx - init.ex;
var changeY = init.sy - init.ey;
if(Math.abs(changeX)>Math.abs(changeY)&&Math.abs(changeY)>init.y) {
//左右事件
if(changeX > ) {
if(type.indexOf("left")!=-) func();
}else{
if(type.indexOf("right")!=-) func();
}
}
else if(Math.abs(changeY)>Math.abs(changeX)&&Math.abs(changeX)>init.x){
//上下事件
if(changeY > ) {
if(type.indexOf("top")!=-) func();
}else{
if(type.indexOf("down")!=-) func();
}
}
else if(Math.abs(changeX)<init.x && Math.abs(changeY)<init.y){
eTime = new Date().getTime();
//点击事件,此处根据时间差细分下
if((eTime - sTime) > ) {
if(type.indexOf("long")!=-) func(); //长按
}
else {
if(type.indexOf("click")!=-) func(); //当点击处理
}
}
if(type.indexOf("end")!=-) func();
}, false);
};

移动端js触摸事件大全的更多相关文章

  1. 移动端-js触摸事件

    开发者工具 在移动开发中,一种较为容易的做法是,先在桌面上开始原型设计,然后再在打算要支持的设备上处理移动特有的部分.多点触摸正是难以在PC上进行测试的那些功能之一,因为大部分的PC都没有触摸输入. ...

  2. 移动端JS 触摸事件基础

    一.手机上的触摸事件   基本事件:   touchstart   //手指刚接触屏幕时触发 touchmove    //手指在屏幕上移动时触发 touchend     //手指从屏幕上移开时触发 ...

  3. js 触摸事件

    js触摸事件 应用在移动端 webkit内核都支持. 触摸事件api https://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html 事件 ...

  4. 移动端touch触摸事件(滑动效果和手势操作)

    一.定义 ①touch是移动端的触摸事件,而且是一组事件,主要有以下事件: touchstart 事件:当手指触摸屏幕的时候触发 touchmove 事件:当手指在屏幕来回滑动的时候触发 touche ...

  5. 移动端 js touch事件

    随着智能手机和平板电脑的普及, 越来越多的人用移动设备浏览网页,我们平时在pc浏览器上用的鼠标事件,比如:click, mouseover等, 已经无法满足移动设备触摸屏的特点,触摸时代的到来,离不开 ...

  6. 移动端 之 触摸事件、Tap事件和swipe事件

    触摸事件 touch是一个事件组,意思不止一个事件,是移动端滑动事件组,touchstart touchmove touchend touchcancel touchstart 当刚刚触摸屏幕的时候触 ...

  7. js触摸事件

    touch事件的绑定 电脑端的mouseDown,mouseUp,mouseMove分别对应移动端的touchstart,touchend,touchmove 下面的代码判断浏览器是电脑端还是移动端, ...

  8. 移动端js触摸touch详解(附带案例源码)

    移动端触摸滑动原理详解案例,实现过程通过添加DOM标签的触摸事件监听,并计算触摸距离,通过距离坐标计算触摸角度,最后通过触摸角度去判断往哪个方向触摸的. 触摸的事件列表 触摸的4个事件: touchs ...

  9. Touch事件 移动端touch触摸事件

    <!-- HTML5 --> <!DOCTYPE html> <html> <head> <title>TouchEvent测试</t ...

随机推荐

  1. cocos2d-x 2.1.4 项目配置过程

    http://cocos2d-x.org 下载cocos2d-x 2.1.4 使用project-creator.py脚本创建Cocos2d-win32 Application项目 1.先下载Wind ...

  2. Pytorch中的torch.cat()函数

    cat是concatnate的意思:拼接,联系在一起. 先说cat( )的普通用法 如果我们有两个tensor是A和B,想把他们拼接在一起,需要如下操作: C = torch.cat( (A,B),0 ...

  3. 记录一个PHP安装redis扩展时的问题

    安装过程:https://www.cnblogs.com/pengyunjing/p/8688320.html 由于我之前安装过该扩展,重新安装时没有执行make clean命令,所以安装好出现了下面 ...

  4. Python2和Python3中print的不同点

    在Python2和Python3中都提供print()方法来打印信息,但两个版本间的print稍微有差异 主要体现在以下几个方面: 1.python3中print是一个内置函数,有多个参数,而pyth ...

  5. D - 文理分科 HYSBZ - 3894(最小割)

    题目链接:https://cn.vjudge.net/contest/281959#problem/D 题目大意:中文题目 具体思路: 首先说一下最小割:在最小代价的前提下,删除一些边之后,能够使得整 ...

  6. linux bash的重定向

    cnblogs原创 下面几种bash重定向各表示什么意思? find / -name passwd > /dev/null >& > /dev/null find / -na ...

  7. Mybatis进阶学习笔记——动态sql

    1.if标签 <select id="queryByNameAndTelephone" parameterType="Customer" resultTy ...

  8. Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  9. Anaconda3配置环境变量

    Anaconda3配置环境变量 有时候在win10安装好Anaconda3后,使用conda命令时依然会出现: C:\Users\dell\PycharmProjects\pytorch>con ...

  10. python实战===教你用微信每天给女朋友说晚安

    但凡一件事,稍微有些重复.我就考虑怎么样用程序来实现它. 这里给各位程序员朋友分享如何每天给朋友定时微信发送”晚安“,故事,新闻,等等··· ···最好运行在服务器上,这样后台挂起来更方便. 准备: ...