获取touchstart,touchmove,touchend 坐标
简单说下如何用jQuery 和 js原生代码获取touchstart,touchmove,touchend 坐标值:
jQuery 代码:
$('#id').on('touchstart',function(e) {
var _touch = e.originalEvent.targetTouches[0];
var _x= _touch.pageX;
}); $('#id').on('touchmove',function(e) {
var _touch = e.originalEvent.targetTouches[0];
var _x= _touch.pageX;
}); $('#id').on('touchend',function(e) {
var _touch = e.originalEvent.changedTouches[0];
var _x= _touch.pageX;
}
js原生代码
document.getElementById("id").addEventListener("touchstart",function(e)
{
var _x=e.touches[0].pageX;
var _y=e.touches[0].pageY;
console.log("start",_x)
})
document.getElementById("id").addEventListener("touchmove",function(e)
{
var _x=e.touches[0].pageX;
var _y=e.touches[0].pageY;
console.log("move",_x)
})
document.getElementById("id").addEventListener("touchend",function(e)
{
var _x=e.changedTouches[0].pageX;
var _y=e.changedTouches[0].pageY;
console.log("end",_x)
})
以上两种办法中 touchend 需要使用changedTouches[0]。
一般我们取第一个手指的坐标,如果有其他要求,可能需要判断手指数量。
if (e.targetTouches.length == 1)
{
//...
}
获取touchstart,touchmove,touchend 坐标的更多相关文章
- JQuery 获取touchstart,touchmove,touchend 坐标
JQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...
- JQuery获取touchstart,touchmove,touchend坐标
$('#id').on('touchstart',function(e) { ].pageX; }); JQuery如上. document.getElementById("id" ...
- 移动端的touchstart,touchmove,touchend事件中的获取当前touch位置
前提:touchstart,touchmove,touchend这三个事件可以通过原生和jq绑定. 原生:document.querySelector("#aa").addEven ...
- 移动端touchstart,touchmove,touchend
近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...
- touchstart,touchmove,touchend触摸事件的小小实践心得
近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...
- jQuery的touchstart,touchmove,touchend的获取位置
$('#webchat_scroller').on('touchstart',function(e) { var touch = e.originalEvent.targetTouches[0]; v ...
- touchstart,touchmove,touchend事件 写法
jQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...
- 手机端touchstart,touchmove,touchend事件,优化用户划入某个可以点击LI的效果
在我们滑动手机的时候,如果LI或者DIV标签可以点击,那么在移动端给用户一个效果 /*id为添加效果LI上的UL的ID,或者是当前DIV的ID*/ function doTouchPublic(id) ...
- 获取移动端 touchend 事件中真正触摸点下方的元素
移动端的touchstart, touchmove, touchend三个事件,拖动元素结束时,获取到了touchend事件, 但是event.touches[0].target所指向的元素却是tou ...
随机推荐
- 1.Java基础-面向对象编程思想(封装继承多态接口)
封装: 1.定义:隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别. 2.封装的目的是:增强安全性和简化编程,使用者不必了解具体的实现细节,而只是要通过外部接口,一特定的 ...
- go 学习笔记(2) --变量、常量、iota、数组
参考网址:https://gobyexample.com 变量 Go中使用全新的关键字var来声明变量.var我们并不陌生,在Javascript 和C#中均有出现.不同的是Go和C#中变量属于强类型 ...
- OAF_OAF Framework常用函数汇总(概念)
2014-12-31 Created By BaoXinjian
- android 布局权重问题(最近布局经常坑爹)
android 布局 权重 With layout_weight you can specify a size ratio between multiple views. E.g. you have ...
- epoll 系列函数简介、与select、poll 的区别
一.epoll 系列函数简介 #include <sys/epoll.h> int epoll_create(int size); int epoll_create1(int flags) ...
- HDU 3849 By Recognizing These Guys, We Find Social Networks Useful(双连通)
HDU 3849 By Recognizing These Guys, We Find Social Networks Useful pid=3849" target="_blan ...
- Wavenet运行
作者:桂. 时间:2017-05-10 19:17:32 链接:http://www.cnblogs.com/xingshansi/p/6832219.html 一.环境 python3.5 Win ...
- AI、机器学习、深度学习、神经网络
1.AI:人工智能(Artificial Intelligence) 2.机器学习:(Machine Learning, ML) 3.深度学习:Deep Learning 人工功能的实现是让机器自己学 ...
- linux 最常用的yum源remi
Remi repository是包含最新版本php和mysql包的linux源. . Enterprise Linux (with EPEL) x86_64 wget https://dl.fedor ...
- Very very important SQL Server article
https://support.microsoft.com/en-us/kb/2964518