From 18810bd4ef20dc87e632d186b768ab276be57d6c Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Tue, 30 Jun 2015 16:15:49 -0400 Subject: [PATCH] Add minified version of the library --- contain-element.min.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contain-element.min.js diff --git a/contain-element.min.js b/contain-element.min.js new file mode 100644 index 0000000..5404f67 --- /dev/null +++ b/contain-element.min.js @@ -0,0 +1,9 @@ + +function containElement(options){var scaleFactor=1;var element=document.getElementById(options.id);var elementWidth=options.width?options.width:element.offsetWidth;var elementHeight=options.height?options.height:element.offsetHeight;if(element.style.position!='absolute') +element.style.position='absolute';if(element.parentElement.style.overflow!='hidden') +element.parentElement.style.overflow='hidden';if(element.parentElement.style.position!='relative'&&element.parentElement.style.position!='absolute'&&element.parentElement.style.position!='fixed') +element.parentElement.style.position='relative';function scaleElement(){var parentWidth=element.parentElement.offsetWidth;var parentHeight=element.parentElement.offsetHeight;if((parentWidth)&&(parentHeight)){if(parentWidth>((parentHeight/(elementHeight*scaleFactor))*(elementWidth*scaleFactor))) +scaleFactor=(parentWidth/elementWidth);else +scaleFactor=(parentHeight/elementHeight);element.style.width=(elementWidth*scaleFactor)+'px';element.style.height=(elementHeight*scaleFactor)+'px';if(parentWidth<(elementWidth*scaleFactor)){switch(options.halign){case'left':element.style.left=0+'px';break;case'right':element.style.left=(0-((elementWidth*scaleFactor)-parentWidth))+'px';break;default:element.style.left=(0-(((elementWidth*scaleFactor)-parentWidth)/2))+'px';}}else{element.style.left=0+'px';} +if((elementHeight*scaleFactor)>parentHeight){switch(options.valign){case'top':element.style.top=0+'px';break;case'bottom':element.style.top=(0-((elementHeight*scaleFactor)-parentHeight))+'px';break;default:element.style.top=(0-(((elementHeight*scaleFactor)-parentHeight)/2))+'px';}}else{element.style.top=0+'px';}}else{window.setTimeout(scaleElement,30);}} +scaleElement();window.onload=function(event){scaleElement();};window.onresize=function(event){scaleElement();};screen.addEventListener('orientationchange',function(){scaleElement();});}