Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
Add Comment
Please, Sign In to add comment