Created
September 17, 2011 23:19
-
-
Save corpix/1224480 to your computer and use it in GitHub Desktop.
Proprotionate size changing(clientside)
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 resizeImgOO(el){ | |
function imgRatio(){ | |
return (el.height / el.width); | |
} | |
function holderRatio(){ | |
return (el.offsetParent.offsetHeight / el.offsetParent.offsetWidth); | |
} | |
function fitToContainer(){ | |
if(imgRatio>holderRatio){ | |
el.height = el.offsetParent.offsetHeight; | |
} else { | |
el.width = el.offsetParent.offsetWidth; | |
} | |
} | |
this.imgRatio = imgRatio; | |
this.holderRatio = holderRatio; | |
this.resize = fitToContainer; | |
} | |
var img = new resizeImgOO(document.getElementById('yourImgId')); | |
img.resize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment