Created
February 2, 2012 00:01
-
-
Save shama/1720264 to your computer and use it in GitHub Desktop.
jmpress.js zoom in and out with + or -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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"); | |
}); | |
})(); |
if(settings.viewPort.width)
settings.viewPort.width = ...;
if(settings.viewPort.height)
settings.viewPort.height = ...;
settings.viewPort is ever set.
width and heigt may be false, which means window scale should not be considered in this dimension. It must stay false even when zooming
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check if the viewPort values are set. if not do not use 0. do not set them at all. leave them undefined.