View difference between Paste ID: czMsjg1C and 4n2QnKds
SHOW: | | - or go back to the newest paste.
1
//image to pinch
2
<img  id="hammerFrame" src="images/tutorials.jpeg" />
3
				<script>
4
					var myElement = document.getElementById('hammerFrame');
5
					var mc = new Hammer.Manager(myElement);
6
					var webpage = document.querySelector("#hammerFrame");
7
					
8
					// create a pinch and rotate recognizer
9
					// these require 2 pointers
10
					var pinch = new Hammer.Pinch();
11
					var rotate = new Hammer.Rotate();
12
					
13
					// we want to detect both the same time
14
					pinch.recognizeWith(rotate);
15
					
16
					// add to the Manager
17
					mc.add([pinch]);
18
					
19
					//Default scales value
20
					var adjustScale = 1;
21
					var adjustDeltaX = 0;
22
					var adjustDeltaY = 0;
23
24
					var currentScale = null;
25
					var currentDeltaX = null;
26
					var currentDeltaY = null;
27
					
28
					mc.on("pinch", function(ev) {
29
					
30
					    var transforms = [];
31
32
						// Adjusting the current pinch/pan event properties using the previous ones set when they finished touching
33
						currentScale = adjustScale * ev.scale;
34
						currentDeltaX = adjustDeltaX + (ev.deltaX / currentScale);
35
						currentDeltaY = adjustDeltaY + (ev.deltaY / currentScale);
36
37
						// Concatinating and applying parameters.
38
						transforms.push('scale(' + currentScale + ')');
39
						//transforms.push('translate(' + currentDeltaX + 'px,' + currentDeltaY + 'px)');
40
						webpage.style.transform = transforms.join(' ');
41
					});
42
43
					mc.on("pinchend", function (ev) {
44
45
						// Saving the final transforms for adjustment next time the user interacts.
46
						adjustScale = currentScale;
47
						adjustDeltaX = currentDeltaX;
48
						adjustDeltaY = currentDeltaY;
49
50
					});
51
				</script>