Created
July 9, 2016 11:39
-
-
Save anonymous/b77761ec9bbf450dab57be668b37f39f to your computer and use it in GitHub Desktop.
JS Bin Touchpad pinch demo // source http://jsbin.com/lotolelele
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Touchpad pinch demo" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
http://experimental.mural.ly/vnext-mural/sticky/200/webglbody { | |
-ms-scroll-rails: none; | |
} | |
#box { | |
height: 100px; | |
width: 100px; | |
background-color: blue; | |
-ms-scroll-rails: none; | |
} | |
</style> | |
</head> | |
<body> | |
<p>Move the box around with your touchpad.<br> | |
Works only in browsers that support the 'wheel' event (Chrome and IE).<br> | |
Supports pinch-zoom in Chrome 36+ on Mac, and with most Windows touchpads. | |
<p><input type=checkbox id=natural checked>My touchpad is configured for natural scrolling | |
<div id=box></div> | |
<script id="jsbin-javascript"> | |
var tx = 0; | |
var ty = 0; | |
var scale = 1; | |
document.addEventListener('wheel', function(e) { | |
e.preventDefault(); | |
if (e.ctrlKey) { | |
var s = Math.exp(-e.deltaY/100); | |
scale *= s; | |
console.log("delta = " + e.deltaY); | |
console.log("scale = " + scale); | |
console.log("s = " + s); | |
} else { | |
var direction = natural.checked ? -1 : 1; | |
tx += e.deltaX * direction; | |
ty += e.deltaY * direction; | |
} | |
var transform = 'translate(' + tx + 'px, ' + ty + 'px) scale(' + scale + ')'; | |
box.style.webkitTransform = transform; | |
box.style.transform = transform; | |
}); | |
</script> | |
<script id="jsbin-source-css" type="text/css">http://experimental.mural.ly/vnext-mural/sticky/200/webglbody { | |
-ms-scroll-rails: none; | |
} | |
#box { | |
height: 100px; | |
width: 100px; | |
background-color: blue; | |
-ms-scroll-rails: none; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var tx = 0; | |
var ty = 0; | |
var scale = 1; | |
document.addEventListener('wheel', function(e) { | |
e.preventDefault(); | |
if (e.ctrlKey) { | |
var s = Math.exp(-e.deltaY/100); | |
scale *= s; | |
console.log("delta = " + e.deltaY); | |
console.log("scale = " + scale); | |
console.log("s = " + s); | |
} else { | |
var direction = natural.checked ? -1 : 1; | |
tx += e.deltaX * direction; | |
ty += e.deltaY * direction; | |
} | |
var transform = 'translate(' + tx + 'px, ' + ty + 'px) scale(' + scale + ')'; | |
box.style.webkitTransform = transform; | |
box.style.transform = transform; | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://experimental.mural.ly/vnext-mural/sticky/200/webglbody { | |
-ms-scroll-rails: none; | |
} | |
#box { | |
height: 100px; | |
width: 100px; | |
background-color: blue; | |
-ms-scroll-rails: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tx = 0; | |
var ty = 0; | |
var scale = 1; | |
document.addEventListener('wheel', function(e) { | |
e.preventDefault(); | |
if (e.ctrlKey) { | |
var s = Math.exp(-e.deltaY/100); | |
scale *= s; | |
console.log("delta = " + e.deltaY); | |
console.log("scale = " + scale); | |
console.log("s = " + s); | |
} else { | |
var direction = natural.checked ? -1 : 1; | |
tx += e.deltaX * direction; | |
ty += e.deltaY * direction; | |
} | |
var transform = 'translate(' + tx + 'px, ' + ty + 'px) scale(' + scale + ')'; | |
box.style.webkitTransform = transform; | |
box.style.transform = transform; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment