uniAPP·屏幕手势滑动监控

uniAPP·屏幕手势滑动监控

【view】

【methods】

/**  
			* 触摸开始  
			**/  
			touchStart(e) {  
				console.log("触摸开始")  
				this.touchStartX = e.touches[0].clientX;  
				this.touchStartY = e.touches[0].clientY;  
			},  

			/**  
			* 触摸结束  
			**/  
			touchEnd(e) {  
				console.log("触摸结束")
				let deltaX = e.changedTouches[0].clientX - this.touchStartX;  
				let deltaY = e.changedTouches[0].clientY - this.touchStartY;  
				if (Math.abs(deltaX) > 50 && Math.abs(deltaX) > Math.abs(deltaY)) {  
					if (deltaX >= 0) {  
						console.log("左滑")  
						uni.navigateTo({ // switchTab  redirectTo  navigateTo reLaunch 关闭所有  navigateBack 隐藏
							url: '/pages/index/index'
						});
					} else {  
						console.log("右滑")  
					}  
				} else if(Math.abs(deltaY) > 50&& Math.abs(deltaX) < Math.abs(deltaY)) {  
					if (deltaY < 0) {  
						console.log("上滑")  
					} else {  
						console.log("下滑")  
					}  
				} else {  
					console.log("可能是误触!")  
				}  
			},    
1,324 Views
分享你的喜爱
linwute
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注