Html5 touch事件

前端之家收集整理的这篇文章主要介绍了Html5 touch事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

“touch”事件鼠标参数位置:
源生:

e.touches[0]

JQuery:

e.originalEvent.touches[0]

在JQuery使用“touch”事件不能直接绑定:

$(...).touchstart(function(){...});            //无效

需要使用“bind()”这类方法来进行绑定

$(...).bind('touchstart',function(){...});

使用源生JavaScript绑定“touch”事件:

var obj = document.getElementById('...');
obj.addEventListener('touchstart',function(e){...},false);

解除绑定方法为:“removeEventListener()”
在解除绑定的时候参数需与绑定的参数相同,且不能解除 绑定匿名函数的事件,如下:

//无效
obj.addEventListener('touchstart',false);
obj.removeEventListener('touchstart',false);

//有效
obj.addEventListener('touchstart',func,false);

该绑定事件的第三个参数解释:

Html5 “touch”事件详解:

猜你在找的程序笔记相关文章