热门推荐
手机端TOUCH天翼云手机端「手机端TOUCH」
2025-02-24 09:07

client / clientY:// 触摸点相对于浏览器窗口viewport的位置

pageX / pageY:// 触摸点相对于页面的位置

screenX /screenY:// 触摸点相对于屏幕的位置

identifier: // touch对象的unique ID

event.preventDefault();// 阻止浏览器默认事件,重要

 

touchstart:  // 手指放到屏幕上的时候触发

touchmove:  // 手指在屏幕上移动的时候触发

touchend:  // 手指从屏幕上拿起的时候触发

touchcancel:  // 系统取消touch事件的时候触发。至于系统什么时候会取消,不详。。

 

<div style='height:500px;width:100%; border:1px solid #000;' id='canvas'>

<script>

var canvas = document.getElementById('canvas');

function touchStart(event){

event.preventDefault();

alert(123)

}

function touchMove(event){

event.preventDefault();

alert(456)

}

function touchEnd(event){

event.preventDefault();

alert(789)

}

    canvas.addEventListener("touchstart", touchStart, false);

    canvas.addEventListener("touchmove", touchMove, false);

    canvas.addEventListener("touchend", touchEnd, false);

    canvas.addEventListener("touchCancel", touchCancel, false);

</script>

 

 

EG:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

 <head>

<title> New document </title>

<meta charset="gb2312" />

<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

<meta name="MobileOptimized" content="320">

<meta name="format-detection" content="telephone=no">

<link rel="apple-touch-icon" href="https://www.cnblogs.com/mrt-yyy/p/touch-icon-iphone.png" />

<link rel="apple-touch-icon" sizes="72x72" href="https://www.cnblogs.com/mrt-yyy/p/touch-icon-ipad.png" />

<link rel="apple-touch-icon" sizes="114x114" href="https://www.cnblogs.com/mrt-yyy/p/touch-icon-iphone4.png" /> 

 </head>

<style>

*{padding:0px;margin:0px; text-align:center;}

.spirit {              

         position: absolute;

         width: 50px;

         height: 50px;

         

}

</style>

 <body>

  <div id="id"style="position:FIXED;width:50px;height:50px; </div>

  <script>

var obj = document.getElementById('id');

obj.addEventListener('touchmove', function(event) {

     // 如果这个元素的位置内只有一个手指的话

    if (event.targetTouches.length == 1) {

     event.preventDefault();// 阻止浏览器默认事件,重要 

        var touch = event.targetTouches[0];

        // 把元素放在手指所在的位置

        obj.style.left = touch.pageX-25 + 'px';

        obj.style.top = touch.pageY-25 + 'px';

        }

}, false);

  </script>

 </body>

    以上就是本篇文章【手机端TOUCH天翼云手机端「手机端TOUCH」】的全部内容了,欢迎阅览 ! 文章地址:http://fabua.ksxb.net/quote/9550.html 
     动态      相关文章      文章      同类文章      热门文章      栏目首页      网站地图      返回首页 海之东岸资讯移动站 http://fabua.ksxb.net/mobile/ , 查看更多