Guest User

Untitled

a guest
Jan 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. function resizeImgOO(el)
  2. {
  3. function imgRatio()
  4. {
  5. return (el.height / el.width);
  6. }
  7. function holderRatio()
  8. {
  9. return (el.offsetParent.offsetHeight / el.offsetParent.offsetWidth);
  10. }
  11. function fitToContainer()
  12. {
  13. if(imgRatio>holderRatio)
  14. {
  15. el.height = el.offsetParent.offsetHeight;
  16. }
  17. else
  18. {
  19. el.width = el.offsetParent.offsetWidth;
  20. }
  21. }
  22.  
  23. this.imgRatio = imgRatio;
  24. this.holderRatio = holderRatio;
  25. this.resize = fitToContainer;
  26. }
  27. var img = new resizeImgOO(document.getElementById('yourImgId'));
  28. img.resize();
Add Comment
Please, Sign In to add comment