Mobile two-finger zoom, rotate

Source: Internet
Author: User

<! DOCTYPE html>


<meta charset= "UTF-8" >
<title> Mobile Two-finger zoom, rotate </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 x=0;
var y=0;
var d=0;
var S=1;

Odiv.addeventlistener (' Touchstart ', function (EV) {
var oldx=x;
var oldy=y;
var Oldd=d;
var olds=s;

function Gett (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= (X1+X2)/2;
var y= (y1+y2)/2;

return {x:x, y:y};
}
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;

Return a2d (Math.atan2 (y,x));
}
function GetS (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 a=x1-x2;
var b=y1-y2;
Return math.sqrt (A*A+B*B);
}

if (ev.targettouches.length==2) {
var Downx=gett (EV). x;
var Downy=gett (ev). Y;
var downd=getd (EV);
var downs=gets (EV);
}

Document.addeventlistener (' Touchmove ', function (EV) {
if (ev.targettouches.length==2) {
X=oldx+gett (EV). X-downx;
Y=oldy+gett (EV). Y-downy;
D=OLDD+DOWND-GETD (EV);
S=olds*gets (EV)/downs;

odiv.style.webkittransform= ' Translate (' +x+ ' px, ' +y+ ' px) scale (' +s+ ') rotate (' +d+ ' deg) ';
}
},false);

Ev.preventdefault ();
},false);
},false);
</script>

<body>
<div id= "Div1" >DIV</div>
</body>

Mobile two-finger zoom, rotate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.