描述: 按住图片进行旋转 让图片跟随鼠标进行对应方向的旋转
touch.js
touch.on('div', 'swipe tap', 'p,li', function(ev){
ev.startRotate();
console.log(ev);
console.log(ev.originEvent);
console.log(ev.type);
console.log(ev.target, ev.srcElement);
console.log(ev.position);
console.log(ev.direction);
console.log(ev.distanceX, ev.distanceY);
console.log(ev.rotation);
console.log(ev.fingersCount);
console.log(ev.distance);
console.log(ev.duration);
});
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div#play{
background: #666;
text-align: center;
}
img{
width: 300px;
}
</style>
</head>
<body>
<div id="play">
<img src="img/timg.png" id="target" />
</div>
<div id="box1"></div>
<script src="./js/touch.js"></script>
<script>
touch.on('img', 'touchstart', function(ev){
ev.startRotate();
});
var img = document.getElementsByTagName('img')[0];
var angle = 0;
touch.on('img', 'rotate', function(ev){
img.style.transform = 'rotate(' + (ev.rotation + angle) + 'deg)';
if(ev.fingerStatus == 'end'){
angle = angle + ev.rotation;
}
});
</script>
</body>
</html>