天天看点

Web移动端之touch事件

touch事件

  • 移动端特有事件,换句话说,触屏设备特有事件,Android,iOS设备
  • 前三个很重要,需要牢牢掌握。

touchstart

  • 手指刚刚触摸到屏幕处触发的事件

touchmove

  • 手指在屏幕上滑动的时候,会不停地触发

touchend

  • 手指离开屏幕的时候触发

touchcancel

  • 被迫终止(比如说突然来电)滑动,触发的事件

怎么绑定这些事件

绑定:on 但是第二次会覆盖

/* 给div绑定touch事件 */
		var dom = document.querySelector("div");

		// touchstart
		//dom.attachEvent();	ie
		/* 手指刚刚触摸到屏幕处触发的事件 */
		dom.addEventListener("touchstart",function(){
			console.log("touchstart");
		});
		/* 手指在屏幕上滑动的时候,会不停地触发 */
		dom.addEventListener("touchmove",function(){
			console.log("touchmove");
		});
		/* 手指离开屏幕的时候触发  */
		dom.addEventListener("touchend",function(){
			console.log("touchend");
		});
           

继续阅读