js移动端判断上下左右划屏
2024-08-26 12:20:02
$(function(){
(function(){ var LSwiperMaker = function(o){ var that = this;
this.config = o;
this.control = false;
this.sPos = {};
this.mPos = {};
this.dire; // this.config.bind.addEventListener('touchstart', function(){ return that.start(); } ,false);
// 这样不对的,event对象只在事件发生的过程中才有效;
this.config.bind.addEventListener('touchstart', function(e){ return that.start(e); } ,false);
this.config.bind.addEventListener('touchmove', function(e){ return that.move(e); } ,false);
this.config.bind.addEventListener('touchend', function(e){ return that.end(e); } ,false); };
LSwiperMaker.prototype.start = function(e){
var point = e.touches ? e.touches[0] : e;
this.sPos.x = point.screenX;
this.sPos.y = point.screenY;
};
LSwiperMaker.prototype.move = function(e){ var point = e.touches ? e.touches[0] : e;
this.control = true;
this.mPos.x = point.screenX;
this.mPos.y = point.screenY; }; LSwiperMaker.prototype.end = function(e){ this.config.dire_h && (!this.control ? this.dire = null : this.mPos.x > this.sPos.x ? this.dire = 'R' : this.dire = 'L');
this.config.dire_h || (!this.control ? this.dire = null : this.mPos.y > this.sPos.y ? this.dire = 'D' : this.dire = 'U'); this.control = false;
this.config.backfn(this); }; window.LSwiperMaker = LSwiperMaker;
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);// 禁止微信touchmove冲突
}());
for(var i= 1;i<7;i++){
function hd(i){
var a = new LSwiperMaker({
bind:document.getElementById("page"+i+""), // 绑定的DOM对象
dire_h:false, //true 判断左右, false 判断上下
backfn:function(o){ //回调事件 //这里写怎样滑动 }
});
}
hd(i);
} });
最新文章
- 如何把Spring制作成jar包,然后在项目里运行。
- wireshark lua脚本
- 继续Wcf记录点滴
- sort如何按指定的列排序
- hibernate将本地SQL查询结果封装成对象
- JS获得事件发出者
- C#语法中一个问号(?)和两个问号(??)的运算符是什么意思?
- Android获取设备隐私 忽略6.0权限管理
- java测试1
- 随学随记之java的数据类型
- .NET运行机制
- django-redis
- Linux创建和挂载XFS文件系统测试实践
- angular2路由与express路由冲突的问题
- asynicio模块以及爬虫应用asynicio模块(高性能爬虫)
- 潭州课堂25班:Ph201805201 django 项目 第四十二课 后台 课程相关,用户组管理 (课堂笔记)
- 第一次学习手游开发:Flappy Bird制作
- docker执行第一个应用
- 工作中经常用到github上优秀、实用、轻量级、无依赖的插件和库
- python上传图片并识别图片