JQuery 获取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;
}
原生写法:
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)
{
//...
}
顺带贴出常用的一句
e.preventDefault();
JQuery 获取touchstart,touchmove,touchend 坐标的更多相关文章
- JQuery获取touchstart,touchmove,touchend坐标
$('#id').on('touchstart',function(e) { ].pageX; }); JQuery如上. document.getElementById("id" ...
- 获取touchstart,touchmove,touchend 坐标
简单说下如何用jQuery 和 js原生代码获取touchstart,touchmove,touchend 坐标值: jQuery 代码: $('#id').on('touchstart',funct ...
- jQuery的touchstart,touchmove,touchend的获取位置
$('#webchat_scroller').on('touchstart',function(e) { var touch = e.originalEvent.targetTouches[0]; v ...
- 移动端的touchstart,touchmove,touchend事件中的获取当前touch位置
前提:touchstart,touchmove,touchend这三个事件可以通过原生和jq绑定. 原生:document.querySelector("#aa").addEven ...
- jquery获取当前元素的坐标
jquery获取当前元素的坐标 1,获取对象 var obj = $("#id号"); 或 var obj = $(this); 实例中我获取的对象是弹出窗口按钮,这样创建的新窗 ...
- 移动端touchstart,touchmove,touchend
近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...
- touchstart,touchmove,touchend触摸事件的小小实践心得
近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...
- 利用jQuery获取鼠标当前的坐标
文字来源:http://www.smalluv.com/jquery_code_106.html jQuery获取当前鼠标坐标位置: <div id="testDiv"> ...
- touchstart,touchmove,touchend事件 写法
jQuery写法: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var ...
随机推荐
- Android之登录时密码的保护
在很多的Android项目中都需要用户登录.注册.这样的话在开发中做好保护用户密码的工作就显得尤为重要.这里我把自己的密码保护方法记录下来. 这是我建了一个保存密码的文件,以便于检查自己保存密码或者上 ...
- CocoaPods安装以及相关问题解决
Mac OS X上安装 Ruby环境 安装RVM $ curl -L https://get.rvm.io | bash -s stable 关闭终端,新开另外一个终端(新打开的终端会自动载入RVM环 ...
- JavaScript Patterns 5.7 Object Constants
Principle Make variables shouldn't be changed stand out using all caps. Add constants as static prop ...
- 编译hadoop2.6.0
具体情况比较曲折:hadoop2.6.0编译不过 错误如下: 这个kms模块始终编译不过,最后得出结论国内的aliyun maven仓库有问题, 在编译hadoop2.2.0 可以通过,因为这个版本的 ...
- Mysql hql字符串字段中是否包含某个字符串,用 find_in_set
有这样一个需求,在Mysql数据库字符串字段(权限)中,有范围在 1 到 N 之间代表不同权限的值,分别被','分开,现在要取出具有某权限的所有成员列表. 创建表: 1 CREATE TABLE us ...
- 【转载】MySQL启多个实例
很多朋友都想在一台服务器上运行多个MySQL Instance,究竟怎么做呢?首先要明晰几个原理, 简称为mysqld读取my.cnf的顺序:第一搜,首先读取/etc/my.cnf,多实例这个配置文件 ...
- socket学习之聊天室
服务端 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...
- Attribute 用法
public class Program { //定制特性也可以应用在其他定制特性上, //应用AttributeUsage,来控制如何应用新定义的特性 [AttributeUsage(Attribu ...
- shell执行mysql命令
难点主要在参数的传递方式吧,不过查资料后发现很简单. 1.使用-e参数传递命令,适用于简单语句 mysql -uuser -ppasswd -e "create database ...
- Windows批处理:自动检查网络连通性
检测网络连通性我用的是丛远到近的方法,即“外网——网关——内网——本机”,脚本的实现也是根据这个顺序用ping来检测,为提高检测速度,这里我只ping了2次,各位可以根据自己的需要进行修改. 使用方法 ...