-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgzoom.js
56 lines (49 loc) · 1.44 KB
/
imgzoom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var hammertime = Hammer(document.getElementById('pinchzoom'), {
transform_always_block: true,
transform_min_scale: 1,
drag_block_horizontal: false,
drag_block_vertical: false,
drag_min_distance: 0
});
var rect = document.getElementById('rect');
var posX=0, posY=0,
scale=1, last_scale,
last_posX=0, last_posY=0;
hammertime.on('touch drag transform dragend', function(ev) {
switch(ev.type) {
case 'touch':
last_scale = scale;
break;
case 'drag':
posX = last_posX + ev.gesture.deltaX;
posY = last_posY + ev.gesture.deltaY;
break;
case 'transform':
scale = Math.max(1, Math.min(last_scale * ev.gesture.scale, 10));
break;
case 'dragend':
last_posX = posX;
last_posY = posY;
break;
}
// transform!
var transform = "";
if(scale > 1){
transform =
"translate3d("+posX+"px,"+posY+"px, 0) " +
"scale3d("+scale+","+scale+", 0) ";
}else{
transform =
"translate3d(0, 0, 0) " +
"scale3d(1, 1, 0) ";
posX = 0;
posY = 0;
last_posX = 0;
last_posY = 0;
}
rect.style.transform = transform;
rect.style.oTransform = transform;
rect.style.msTransform = transform;
rect.style.mozTransform = transform;
rect.style.webkitTransform = transform;
});