HTML5屏幕触摸的四个事件touchstart、touchmove、touchend、touchcancel

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <title>touch 事件</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        .box{
            height: 200px;
            width: 200px;
            background: red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        /*
        * 1.touchstart    手指刚刚触发到屏幕的时候
        * 2.touchmove     手指在屏幕上滑动的时候
        * 3.touchend      手指离开屏幕的时候
        * 4.touchcancel   ** 被迫终止滑动离开  (系统终止)
        * */

        /*怎么样去绑定这些事件*/
        var box = document.querySelector('.box');

        /*绑定touchstart*/
        box.addEventListener('touchstart',function(e){
            console.log('touchstart');
            console.log(e);
        });

        /*绑定touchmove*/
        box.addEventListener('touchmove',function(e){
            console.log('touchmove');
            console.log(e);
        });

        /*绑定touchend*/
        box.addEventListener('touchend',function(e){
           console.log('touchend');
            console.log(e);
        });


        /*
        * targetTouches 当前目标元素的所有触摸点的集合
        * touches  当前屏幕的所有触摸点集合
        * changedTouches 当前改变的触摸点集合
        *
        * **注意** 在touchend事件当中是没有 targettouches touches 但是有changedtouches
        *
        * */


        /*每一个触摸点有一些属性*/
        /*clientX:触摸目标在视口中的X坐标。
        clientY:触摸目标在视口中的Y坐标。
        pageX:触摸目标在页面中的x坐标。
        pageY:触摸目标在页面中的y坐标。
        screenX:触摸目标在屏幕中的x坐标。
        screenY:触摸目标在屏幕中的y坐标。*/



    </script>
</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值