Event binded at document level (window.document, window.document.body, or window) are treated as passive and can't be prevented. You should specify that the event is not passive with { passive: false }
as third parameter of your addEventListener
function. See this link for more info.
In your case :
document.addEventListener('wheel', function(e) {
e.preventDefault();
e.stopPropagation();
if (e.ctrlKey) {
var s = Math.exp(-e.deltaY / 100);
scale *= s;
} else {
var direction = 1; //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;
}, {
passive: false // Add this
});
Moreover it won't work on codepen due to the use of the iframe as event is binded on the iframe and not on the codepen page itself.
e.preventDefault();
which doesn't work. – Plumb