Last active
August 29, 2015 14:10
-
-
Save josesayago/860d2445cceb5b4b470d to your computer and use it in GitHub Desktop.
KineticJS dynamic scale
This file contains hidden or 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
function _dynamicScale( params ) { | |
gutter = 200; | |
initialScale = params.zoom; | |
initialWidth = jQuery('#canvasEditor').innerWidth(); | |
initialHeight = jQuery('#canvasEditor').innerHeight(); | |
width = initialWidth / initialHeight * ( jQuery(window.top).innerHeight() - gutter ); | |
height = jQuery(window.top).innerHeight() - gutter; | |
xScale = ( width / initialWidth ) * initialScale.x; | |
yScale = ( height / initialHeight ) * initialScale.y; | |
scale = { x: xScale, y: yScale }; | |
params.zoom = newScale; | |
params.width = width; | |
params.height = height; | |
stage.scale( params.zoom ); | |
stage.size({ | |
width: params.width, | |
height: params.height | |
}); | |
jQuery('#canvasEditor').css({ | |
width: params.width, | |
height: params.height | |
}); | |
stage.draw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment