触屏touch事件 | 说明 |
---|---|
touchstart | 手指在触摸到一个dom元素时触发 |
touchumove | 手指在一个dom元素上滑动时触发 |
touchend | 手指从一个dom元素上移开时触发 |
代码示例,主页要在控制台点击下面图标进入手机显示模式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
width: 800px;
height: 800px;
text-align: center;
font-size: 160px;
line-height: 800px;
background-color: pink;
}
</style>
</head>
<body>
<div></div>
<script>
var div=document.querySelector('div');
div.addEventListener('touchstart',function () {
console.log('我摸了你');
div.innerHTML='我被摸了';
})
div.addEventListener('touchmove',function () {
console.log('我继续摸你');
div.innerHTML='我正在被摸';
})
div.addEventListener('touchend',function () {
console.log('轻轻的我走了');
div.innerHTML='它走了';
})
</script>
</body>
</html>