Skip to content

Instantly share code, notes, and snippets.

@Monichre
Created October 30, 2018 14:40
Show Gist options
  • Save Monichre/c1667a03961f6072af9d28d3ae7a5fed to your computer and use it in GitHub Desktop.
Save Monichre/c1667a03961f6072af9d28d3ae7a5fed to your computer and use it in GitHub Desktop.
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