Add a function to return the current scale factor of the contained element

This commit is contained in:
Kevin MacMartin 2015-09-04 14:26:56 -04:00
parent 9ea6f875b4
commit 7a59f6bc3c
3 changed files with 9 additions and 2 deletions

View file

@ -13,7 +13,6 @@ The plugin scales an element to the minimum size required for it to be completel
* Pure JavaScript with no dependencies
* Configures the horizontal and vertical alignment of the contained element
* Can detect the native size or have it specified at runtime
* Includes function to update the size and position
## Usage
@ -35,6 +34,11 @@ window.onload = function() {
};
```
## Functions
* `update()`: Update the size and position of the contained element.
* `getScale()`: Return the current scale factor being applied to the contained element.
## Credits
Written by [Williams New York](http://williamsnewyork.com)

View file

@ -74,5 +74,8 @@ function ContainElement(options) {
// Add an external scale and anchor update function
this.update = updateContain;
// Add function to return the current scale factor
this.getScale = function() { return scaleFactor; };
}

View file

@ -1 +1 @@
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}
function ContainElement(e){function t(){var o=i.parentElement.offsetWidth,a=i.parentElement.offsetHeight;if(o&&a){if(l=o>a/(n*l)*s*l?o/s:a/n,i.style.width=s*l+"px",i.style.height=n*l+"px",s*l>o)switch(e.halign){case"left":i.style.left="0px";break;case"right":i.style.left=0-(s*l-o)+"px";break;default:i.style.left=0-(s*l-o)/2+"px"}else i.style.left="0px";if(n*l>a)switch(e.valign){case"top":i.style.top="0px";break;case"bottom":i.style.top=0-(n*l-a)+"px";break;default:i.style.top=0-(n*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,n=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,this.getScale=function(){return l}}