移动端touch事件案例详解

<!doctype html><html lang="en"><head>    <meta charset="UTF-8">    <title>移动端touch事件</title>    <style>        #div{            width...
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>移动端touch事件</title>
    <style>
        #div{
            width: 100%;
            height: 800px;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <div id="div"></div>
    <script type="text/javascript">
        var div = document.getElementById('div');
        div.addEventListener('touchstart',function(event){
            // var ev = event || ev;
            event.preventDefault();
            div.style.background = 'red';
        },false);
        //touchstart 当手指触摸屏幕时
        div.addEventListener('touchmove',function(event){
            // var ev = event || ev;
            event.preventDefault();
            div.style.background = 'blue';
        },false);
        //touchmove 当手指在屏幕上移动时
        div.addEventListener('touchend',function(event){
            // var ev = event || ev;
            event.preventDefault();
            div.style.background = 'yellow';
        },false);
        //touchend 当手指划过屏幕时
    </script>
</body>
</html>

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
admin
admin

651 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章