Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@i8degrees
Forked from anonymous/index.html
Created July 9, 2016 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i8degrees/1f891b83081419669660223b7df2466b to your computer and use it in GitHub Desktop.
Save i8degrees/1f891b83081419669660223b7df2466b to your computer and use it in GitHub Desktop.
JS Bin Touchpad pinch demo // source http://jsbin.com/lotolelele
<!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>
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;
}
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