<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>移动端双指旋转</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0,maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<style>
#div1{
width:200px;
height:200px;
background: red;
margin: 50px auto;
font-size: 40px;
color: #fff;
}
</style>
<script>
function a2d(n){
return n*180/Math.PI;
}
document.addEventListener(‘DOMContentLoaded‘,function(){
var oDiv=document.querySelector(‘#div1‘);
var d=0;
oDiv.addEventListener(‘touchstart‘,function(ev){
var oldD=d;
function getD(ev){
var x1=ev.targetTouches[0].pageX;
var y1=ev.targetTouches[0].pageY;
var x2=ev.targetTouches[1].pageX;
var y2=ev.targetTouches[1].pageY;
var x=x2-x1;
var y=y1-y2;
var d=a2d(Math.atan2(y,x));
return d;
}
if(ev.targetTouches.length==2){
var downD=getD(ev);
}
document.addEventListener(‘touchmove‘,function(ev){
if(ev.targetTouches.length==2){
d=oldD+downD-getD(ev);
oDiv.style.WebkitTransform=‘rotate(‘+d+‘deg)‘;
}
},false);
ev.preventDefault();
},false);
},false);
</script>
</head>
<body>
<div id="div1">DIV</div>
</body>
</html>