Skip to content

Instantly share code, notes, and snippets.

@shama
Created February 2, 2012 00:01
Show Gist options
  • Save shama/1720264 to your computer and use it in GitHub Desktop.
Save shama/1720264 to your computer and use it in GitHub Desktop.
jmpress.js zoom in and out with + or -
/**
* Viewport Key Zoom In & Out
* Press + and - to zoom the viewport in and out.
*/
(function() {
'use strict';
$.jmpress("defaults").viewPort.keyZoomAmount = 100;
$.extend(true, $.jmpress('defaults').keyboard.keys, {
187: 'zoomin' // plus
,189: 'zoomout' // minus
});
$.jmpress("register", "zoomin", function() {
var settings = $(this).jmpress('settings');
if ( settings.viewPort.width ) {
settings.viewPort.width += settings.viewPort.keyZoomAmount;
}
if ( settings.viewPort.height ) {
settings.viewPort.height += settings.viewPort.keyZoomAmount;
}
$(this).jmpress("select", $(this).jmpress("active"), "resize");
});
$.jmpress("register", "zoomout", function() {
var settings = $(this).jmpress('settings');
if ( settings.viewPort.width ) {
settings.viewPort.width -= settings.viewPort.keyZoomAmount;
}
if ( settings.viewPort.height ) {
settings.viewPort.height -= settings.viewPort.keyZoomAmount;
}
$(this).jmpress("select", $(this).jmpress("active"), "resize");
});
})();
@shama
Copy link
Author

shama commented Feb 2, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment