Skip to content

Instantly share code, notes, and snippets.

@Scarbous
Created April 5, 2018 11:46
Show Gist options
  • Save Scarbous/d8b44fbe2e9b1ddfb7d81f8049faf0d8 to your computer and use it in GitHub Desktop.
Save Scarbous/d8b44fbe2e9b1ddfb7d81f8049faf0d8 to your computer and use it in GitHub Desktop.
jQuery Zoom-Trigger
(function($, w, d) {
function scroll(e) {
if (!e.ctrlKey) return;
var oe = e.originalEvent,
t = oe.wheelDelta > 0 || oe.detail < 0 ? "In" : "Out";
if (t) trigger(t, e);
}
function keyDown(e) {
if (!e.ctrlKey) return;
var w = e.which,
t =
[189, 109].indexOf(w) >= 0 ? "In" : [187, 107].indexOf(w) >= 0 ? "Out" : [48, 96].indexOf(w) >= 0 ? "Reset" : false;
if (t) trigger(t, e);
}
function trigger(t, e) {
$(w).trigger('zoom'+t,[e])
.trigger('zoom',[e]);
}
$(w).on("mousewheel DOMMouseScroll", scroll);
$(d).on("keydown", keyDown);
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment