Created
June 6, 2014 14:45
-
-
Save weiland/b4015d7325b49e18726a to your computer and use it in GitHub Desktop.
Calculate the new size of an element w*h with a new width or height.
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
(function CalculateNewSizes(){ | |
var width, height, nWidth, nHeight, tmp; | |
tmp = prompt('Current dimensions 123x1234: ').split('x'); | |
width = tmp[0]; | |
height = tmp[1]; | |
tmp = prompt('Set a new value for width. (prefix h for new Height)').replace(/ /g, ''); | |
if(tmp.indexOf('h') !== -1) { | |
nHeight = tmp.replace(/h/, ''); | |
nWidth = parseInt(width*nHeight/height); | |
} else { | |
nWidth = tmp; | |
nHeight = parseInt(height*nWidth/width); | |
} | |
alert('new width: ' + nWidth + "\n" + 'new height: ' + nHeight); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment