推广 热搜:   公司  企业  中国  快速    行业  上海  设备  未来 

手机端TOUCH天翼云手机端「手机端TOUCH」

   日期:2025-02-24     移动:http://fabua.ksxb.net/mobile/quote/9550.html

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>

本文地址:http://fabua.ksxb.net/quote/9550.html    海之东岸资讯 http://fabua.ksxb.net/ , 查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


相关最新动态
推荐最新动态
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  粤ICP备2023022329号