15.移动端touch触摸事件

268 阅读1分钟

1.ntouchstart: 手指触摸dom元素

2.ntouchmove: 手指在dom元素上移动

3.ntouchend: 手指离开dom元素
4.案例分析

<!DOCTYPE html>
<html lang="CH-zn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>移动端三个事件</title>
    <style type="text/css">
     div{
         width: 200px;height: 200px;
         background-color: pink;
     }
    </style>
   
</head>
<script type="text/javascript">
        // 写在上面需要加wind 事件
        window.addEventListener('load',function(){
        // 1.获取元素
        var  div = document.querySelector('div');
        // 2.手指触摸
         div.addEventListener('touchstart',function(){
            console.log('我摸了你') ;
         } )
       // 3.手机点击 touchmove
        div.addEventListener('touchmove',function(){
            console.log('我移动了你') ;
        })
        // 4.我手机头离开了你
        div.addEventListener('touchend',function(){
            document.write('我走了-') ;
        })
    

        })
       
</script>

</head>



<body>
    <div id="c_nav" class="c-nav">
     


</body>
</html>