mirror of
https://github.com/WilliamsNY/contain-element.git
synced 2024-11-24 06:31:26 -05:00
Touch up comments and formatting
This commit is contained in:
parent
f5abdade9a
commit
09752ed55a
1 changed files with 10 additions and 10 deletions
|
@ -4,10 +4,10 @@ function ContainElement(options) {
|
||||||
var elementWidth = options.width || element.offsetWidth;
|
var elementWidth = options.width || element.offsetWidth;
|
||||||
var elementHeight = options.height || element.offsetHeight;
|
var elementHeight = options.height || element.offsetHeight;
|
||||||
|
|
||||||
// Apply required attributes to the element and its parents if they aren't already set
|
// Apply required attributes to the element and its parents
|
||||||
element.style.position = 'absolute';
|
element.style.position = 'absolute';
|
||||||
element.parentElement.style.overflow = 'hidden';
|
element.parentElement.style.overflow = 'hidden';
|
||||||
if (['relative', 'absolute', 'fixed'].indexOf(window.getComputedStyle(element.parentElement,null).getPropertyValue('position')) === -1)
|
if (['relative', 'absolute', 'fixed'].indexOf(window.getComputedStyle(element.parentElement, null).getPropertyValue('position')) === -1)
|
||||||
element.parentElement.style.position = 'relative';
|
element.parentElement.style.position = 'relative';
|
||||||
|
|
||||||
function updateContain() {
|
function updateContain() {
|
||||||
|
@ -30,16 +30,16 @@ function ContainElement(options) {
|
||||||
if (parentWidth < (elementWidth * scaleFactor)) {
|
if (parentWidth < (elementWidth * scaleFactor)) {
|
||||||
switch(options.halign) {
|
switch(options.halign) {
|
||||||
case 'left':
|
case 'left':
|
||||||
// anchor horizontally to the left of the parent element
|
// Anchor horizontally to the left of the parent element
|
||||||
element.style.left = 0 + 'px';
|
element.style.left = 0 + 'px';
|
||||||
break;
|
break;
|
||||||
case 'right':
|
case 'right':
|
||||||
// anchor horizontally to the right of the parent element
|
// Anchor horizontally to the right of the parent element
|
||||||
element.style.left = (0 - ((elementWidth * scaleFactor) - parentWidth)) + 'px';
|
element.style.left = (0 - ((elementWidth * scaleFactor) - parentWidth)) + 'px';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// anchor horizontally to the center of the parent element
|
// Anchor horizontally to the center of the parent element
|
||||||
element.style.left = (0 - (((elementWidth * scaleFactor) - parentWidth) / 2 )) + 'px';
|
element.style.left = (0 - (((elementWidth * scaleFactor) - parentWidth) / 2)) + 'px';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
element.style.left = 0 + 'px';
|
element.style.left = 0 + 'px';
|
||||||
|
@ -49,16 +49,16 @@ function ContainElement(options) {
|
||||||
if ((elementHeight * scaleFactor) > parentHeight) {
|
if ((elementHeight * scaleFactor) > parentHeight) {
|
||||||
switch(options.valign) {
|
switch(options.valign) {
|
||||||
case 'top':
|
case 'top':
|
||||||
// anchor vertically to the top of the parent element
|
// Anchor vertically to the top of the parent element
|
||||||
element.style.top = 0 + 'px';
|
element.style.top = 0 + 'px';
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
case 'bottom':
|
||||||
// anchor veritcally to the bottom of the parent element
|
// Anchor veritcally to the bottom of the parent element
|
||||||
element.style.top = (0 - ((elementHeight * scaleFactor) - parentHeight)) + 'px';
|
element.style.top = (0 - ((elementHeight * scaleFactor) - parentHeight)) + 'px';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// anchor vertically to the center of the parent element
|
// Anchor vertically to the center of the parent element
|
||||||
element.style.top = (0 - (((elementHeight * scaleFactor) - parentHeight) / 2 )) + 'px';
|
element.style.top = (0 - (((elementHeight * scaleFactor) - parentHeight) / 2)) + 'px';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
element.style.top = 0 + 'px';
|
element.style.top = 0 + 'px';
|
||||||
|
|
Loading…
Reference in a new issue