简单说下如何用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 坐标的更多相关文章

  1. JQuery 获取touchstart,touchmove,touchend 坐标

    JQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...

  2. JQuery获取touchstart,touchmove,touchend坐标

    $('#id').on('touchstart',function(e) { ].pageX; }); JQuery如上. document.getElementById("id" ...

  3. 移动端的touchstart,touchmove,touchend事件中的获取当前touch位置

    前提:touchstart,touchmove,touchend这三个事件可以通过原生和jq绑定. 原生:document.querySelector("#aa").addEven ...

  4. 移动端touchstart,touchmove,touchend

    近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...

  5. touchstart,touchmove,touchend触摸事件的小小实践心得

    近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...

  6. jQuery的touchstart,touchmove,touchend的获取位置

    $('#webchat_scroller').on('touchstart',function(e) { var touch = e.originalEvent.targetTouches[0]; v ...

  7. touchstart,touchmove,touchend事件 写法

    jQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...

  8. 手机端touchstart,touchmove,touchend事件,优化用户划入某个可以点击LI的效果

    在我们滑动手机的时候,如果LI或者DIV标签可以点击,那么在移动端给用户一个效果 /*id为添加效果LI上的UL的ID,或者是当前DIV的ID*/ function doTouchPublic(id) ...

  9. 获取移动端 touchend 事件中真正触摸点下方的元素

    移动端的touchstart, touchmove, touchend三个事件,拖动元素结束时,获取到了touchend事件, 但是event.touches[0].target所指向的元素却是tou ...

随机推荐

  1. Jmeter --- 逻辑控制之if控制器

    一.背景 在实际工作中,当使用Jmeter做性能脚本或者接口脚本时,有可能会遇到需要对不同的条件做不同的操作,基于这种诉求,在Jmeter中可使用if控制器来实现 二.实际操作 逻辑控制器位置: 在线 ...

  2. RMAN性能监控

    RMAN性能调优相关视图 视图名 说明 v$rman_backup_job_details 备份job信息 v$backup_async_io 当前正在运行的.最近完成的备份和restore操作的rm ...

  3. php 设置自动加载某个页面

    首先要找到Php.ini文件. 新建一个php文件,使用phpinfo(); 之后找到 Loaded Configuration File 指定的路径就是php.ini文件 打开文件,找到 auto_ ...

  4. jenkins 执行ssh 远程linux执行命令

    1.远程机器编写脚本: 脚本名称为: /app/jboss/jboss-as/logs/ALL_SERVICE_STOP.sh 功能为:停止某个服务器某个目录下面的所有应用 #!/bin/bash p ...

  5. CSS选择器、层叠相关的基础知识

    CSS是Cascading Style Sheets的英文缩写,即层叠样式表.CSS2.1是W3C于2007年发布,现在推荐使用的.CSS3现在还处于开发中,有部分浏览器的新版本支持. 1. CSS ...

  6. [面试题] Find next higher number with same digits

    Find next higher number with same digits. Example 1 : if num = 25468, o/p = 25486 Example 2 : if num ...

  7. Vagrant安装指南

    ubuntu的易用性很高,安装很简单,颜值也高,但是我工作中经常使用centos,我希望我的笔记本也是centos,但是,centos颜值太低,配置文件很复杂,不想弄这个太麻烦,于是,我想到了Vagr ...

  8. ajaxfileupload异步上传附件添加參数的方法

    1.js文件 // JavaScript Document jQuery.extend({ createUploadIframe: function(id, uri) { //create frame ...

  9. 一些通用性的haproxy调优tips

    一.硬件和系统 haproxy是单线程,非阻塞,事件驱动,所以会最大化利用单个CPU内核,选择haproxy的硬件时要关注如下:   1.选择CPU的时候,选择高主频,大缓存的型号,比内核数更重要 2 ...

  10. [转载] C++的那些事:你真的了解引用吗

    我转载了roony的一篇文章 C++的那些事:你真的了解引用吗 以备以后可以查到. 一.引用的本质是什么 说到引用,一般C++的教材中都是这么定义的: 1.引用就是一个对象的别名. 2.引用不是值不占 ...