Skip to content

Instantly share code, notes, and snippets.

@timohausmann
Created March 20, 2013 09:01
Show Gist options
  • Select an option

  • Save timohausmann/5203276 to your computer and use it in GitHub Desktop.

Select an option

Save timohausmann/5203276 to your computer and use it in GitHub Desktop.
Javascript: restrain maximum dimensions
var aspectRatio = width / height;
if( height > APP.height ) {
height = APP.height;
width = height * aspectRatio;
} else if( width > APP.width ) {
width = APP.width;
height = width / aspectRatio;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment