<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,height=device-height, user-scalable=no,initial-scale=1, minimum-scale=1, maximum-scale=1 ">
<title>Document</title>
<style>
#myDiv{width:200px;height:200px;margin: 0 auto;}
#myDiv2{width:40px;height: 40px;border-radius: 20px; background-color:deeppink;position: absolute;top:0;left:0;z-index:0}
</style>
</head>
<body>
<div id="myDivStart">Touch start(0, 0)</div>
<div id="myDivmove">Touch move(0, 0)</div>
<div id="myDivend">Touch end(0, 0)</div>
<div id="myradius">Touch radius(0, 0)</div>
<div id="force">Touch force:</div>
<div id="rotateAngle">Touch rotationAngle:</div>
<div id="myDiv2"></div>
</body>
<script>
function touchEvent(event){
event = event || window.event;
var mydiv2 = document.getElementById('myDiv2');
var myDivStart = document.getElementById('myDivStart');
var myDivmove = document.getElementById('myDivmove');
var myDivend = document.getElementById('myDivend');
var myradius = document.getElementById('myradius');
var force = document.getElementById('force');
var rotationAngle = document.getElementById('rotateAngle');
var coordinateX = event.changedTouches[0].clientX;
var coordinateY = event.changedTouches[0].clientY;
mydiv2.style.left = parseFloat(coordinateX)-20 + 'px';
mydiv2.style.top = parseFloat(coordinateY)-20 + 'px';
myradius.innerHTML = "Touch radius:(" + event.changedTouches[0].radiusX.toFixed(2) + ' ,' + event.changedTouches[0].radiusY.toFixed(2) + ")";
rotationAngle.innerHTML = "Touch rotationAngle:" + event.changedTouches[0].rotationAngle;
force.innerHTML = "Touch force:" + event.changedTouches[0].force.toFixed(3);
var intX = parseInt(coordinateX);
var intY = parseInt(coordinateY);
switch(event.type){
case "touchstart" :
myDivStart.innerHTML = "Touch started:(" + event.touches[0].clientX.toFixed(2) + ' ,' + event.touches[0].clientY.toFixed(2) + ")";
console.log(event);
break;
case "touchmove" :
event.preventDefault();// 阻止滚动
myDivmove.innerHTML = "Touch moved:(" + intX + ' ,' + intY + ")";
console.log(event);
break;
case "touchend" :
myDivend.innerHTML = "Touch end:(" + intX + ' ,' + intY + ")";
console.log(event);
myradius.innerHTML = "Touch radius:(0.00,0.00)"
force.innerHTML = "Touch force:0.00" ;
break;
}
}
document.addEventListener("touchstart",touchEvent,false);
document.addEventListener("touchmove",touchEvent,false);
document.addEventListener("touchend",touchEvent,false);
</script>
</html>