contain-element/contain-element.min.js
2015-07-02 13:06:08 -04:00

1 line
No EOL
894 B
JavaScript

function ContainElement(e){function t(){var n=i.parentElement.offsetWidth,a=i.parentElement.offsetHeight;if(n&&a){if(l=n>a/(o*l)*s*l?n/s:a/o,i.style.width=s*l+"px",i.style.height=o*l+"px",s*l>n)switch(e.halign){case"left":i.style.left="0px";break;case"right":i.style.left=0-(s*l-n)+"px";break;default:i.style.left=0-(s*l-n)/2+"px"}else i.style.left="0px";if(o*l>a)switch(e.valign){case"top":i.style.top="0px";break;case"bottom":i.style.top=0-(o*l-a)+"px";break;default:i.style.top=0-(o*l-a)/2+"px"}else i.style.top="0px"}else window.setTimeout(t,30)}var l=1,i=document.getElementById(e.id),s=e.width||i.offsetWidth,o=e.height||i.offsetHeight;i.style.position="absolute",i.parentElement.style.overflow="hidden",-1===["relative","absolute","fixed"].indexOf(window.getComputedStyle(i.parentElement,null).getPropertyValue("position"))&&(i.parentElement.style.position="relative"),t(),this.update=t}