mirror of
https://github.com/WilliamsNY/contain-element.git
synced 2024-12-28 01:14:34 -05:00
Merge branch 'master' into gh-pages
This commit is contained in:
commit
f65377b30b
2 changed files with 5 additions and 5 deletions
|
@ -4,7 +4,7 @@ A JavaScript plugin to contain an element within its parent element.
|
|||
|
||||
## Description
|
||||
|
||||
The plugin scales an element to the minimum size required for it to be completely contained within its parent, and retains its original aspect ratio by cropping portions that don't fit based on its vertical and horizontal alignment (by default both are set to: `middle`).
|
||||
The plugin scales an element to the minimum size required for it to be completely contained within its parent, and retains its original aspect ratio by cropping portions that don't fit based on its vertical and horizontal alignment (by default both are set to: `center`).
|
||||
|
||||
[Demo](http://williamsny.github.io/contain-element/)
|
||||
|
||||
|
@ -23,8 +23,8 @@ window.onload = function() {
|
|||
id: 'element', // the id of the element to be contained
|
||||
width: '100', // (optional) element width in pixels (unset: element width)
|
||||
height: '100', // (optional) element height in pixels (unset: element height)
|
||||
valign: 'top', // (optional) vertical alignment: top|bottom (unset: middle)
|
||||
halign: 'left' // (optional) horizontal alignment: left|right (unset: middle)
|
||||
valign: 'top', // (optional) vertical alignment: top|bottom (unset: center)
|
||||
halign: 'left' // (optional) horizontal alignment: left|right (unset: center)
|
||||
});
|
||||
|
||||
// (example) update the size and positioning on window resize
|
||||
|
|
|
@ -40,7 +40,7 @@ function ContainElement(options) {
|
|||
element.style.left = (0 - ((elementWidth * scaleFactor) - parentWidth)) + 'px';
|
||||
break;
|
||||
default:
|
||||
// anchor horizontally to the middle of the parent element
|
||||
// anchor horizontally to the center of the parent element
|
||||
element.style.left = (0 - (((elementWidth * scaleFactor) - parentWidth) / 2 )) + 'px';
|
||||
}
|
||||
} else {
|
||||
|
@ -59,7 +59,7 @@ function ContainElement(options) {
|
|||
element.style.top = (0 - ((elementHeight * scaleFactor) - parentHeight)) + 'px';
|
||||
break;
|
||||
default:
|
||||
// anchor vertically to the middle of the parent element
|
||||
// anchor vertically to the center of the parent element
|
||||
element.style.top = (0 - (((elementHeight * scaleFactor) - parentHeight) / 2 )) + 'px';
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue