Skip to content

Instantly share code, notes, and snippets.

@josesayago
Last active August 29, 2015 14:10
Show Gist options
  • Save josesayago/860d2445cceb5b4b470d to your computer and use it in GitHub Desktop.
Save josesayago/860d2445cceb5b4b470d to your computer and use it in GitHub Desktop.
KineticJS dynamic scale
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