h5触摸事件-判断上下滑动
2024-08-27 00:10:17
// 判断上下滑动
var startX = 0,
startY = 0;
function touchStart(evt){
try{
var touch = evt.touches[0], //获取第一个触点
x = Number(touch.pageX), //页面触点X坐标
y = Number(touch.pageY); //页面触点Y坐标
//记录触点初始位置
startX = x;
startY = y;
}catch(e){
console.log(e.message)
}
} function touchMove(evt){
try{
var touch = evt.touches[0], //获取第一个触点
x = Number(touch.pageX), //页面触点X坐标
y = Number(touch.pageY); //页面触点Y坐标
//判断滑动方向
if (y - startY<0) {
console.log('上滑了!');
var mainView = myApp.addView('.view-main', {domCache: true});
mainView.router.load({pageName: 'friendCircle'});
}
}catch(e){
console.log(e.message);
}
} // function touchEnd(evt){
// try{
// var touch = evt.touches[0], //获取第一个触点
// x = Number(touch.pageX), //页面触点X坐标
// y = Number(touch.pageY); //页面触点Y坐标
// //判断滑动方向
// if (y - startY<0) {
// console.log('上滑了!');
// }
// }catch(e){
// console.log(e.message);
// console.log("end");
// }
// } //绑定事件
function bindEvent(){
document.addEventListener('touchstart',touchStart,false);
document.addEventListener('touchmove',touchMove,false);
// document.addEventListener('touchend',touchEnd,false);
} bindEvent();
参考:http://blog.csdn.net/bbsyi/article/details/52108599
最新文章
- 关于VS中文件属性的解释
- 多线程socket编程示例
- jquery的ajax()函数传值中文乱码解决方法介绍
- MS WORD 表格自己主动调整列宽,自己主动变美丽,依据内容自己主动调整
- c++ 概念及学习/c++ concept&;learning(三)
- mysql日期加减问题
- Window下 Qt 编译MySQL驱动(居然用到了动态库格式转换工具)
- Java语言程序设计基础篇第10版第5章习题答案
- vim删除.swp
- postgresql数据库varchar、char、text的比较
- Docker的基本组成
- Sword protobuf学习一
- windows下使用RedisCluster集群简单实例
- spring boot 之使用mapstruct
- 关于VS 工具箱灰色,不可用的解决方案
- 用isNaN函数来判断是否只能输入正负数字
- 《火星救援》NASA惊现lisp
- 对selenium自动化框架重构
- bloom filter + murmurhash
- jsp另外五大内置对象之response-操作重定向
热门文章
- eNSP——实现OSPF与ACL综合实验
- TypeScript(二)使用Webpack搭建环境
- Stream知识点总结及源码阅读
- 综述论文翻译:A Review on Deep Learning Techniques Applied to Semantic Segmentation
- 1.IO的演进
- AVR单片机教程——随机点亮LED
- Authorization
- ASP.NET MVC 5 伪静态之支持*.html路由
- [A]System.Web.WebPages.Razor.Configuration.HostSection 无法强制转换为 [B]解决办法
- linux的scp命令可以在linux服务器之间复制文件和目录