Kind: global class
Npmpackage:
- Clamp
- new Clamp()
- .X :
string
- .Y :
string
- .XY :
string
- .set(source, type, buffer)
Import from ad-view
// importing into an ES6 class import { Clamp } from 'ad-view'
Utility for resizing a DOM element to the size of all its content, sort of like shrink wrapping.
This will clamp the bounds and potentially move the x and y so that visually the content stays where it is. There is the option to clamp both horizontally and vertically, or you can just do one. Additionally there is a optional object to add some buffer space on any of the sides.
Example
// clamp both directions
Clamp.set( View.main.myDiv, Clamp.XY );
// clamp both directions while adding some buffer padding on each side
Clamp.set( View.main.myDiv, Clamp.XY, {
top : 5,
left : 10,
bottom : 5,
right : 10
});
// clamp only horizontally and add a buffer padding on the left
Clamp.set( View.main.myDiv, Clamp.X, {
left : 10
});
Synonymous with "clampX" - clamp on the horizontal direction only
Kind: static constant of Clamp
Synonymous with "clampY" - clamp on the vertical direction only
Kind: static constant of Clamp
Synonymous with "clampXY" - clamp on all sides
Kind: static constant of Clamp
Resizes and moves the source element horizontally and/or vertically, relative to all its children.
Kind: static method of Clamp
Param | Type | Description |
---|---|---|
source | element |
The DOM element to resize and move. |
type | string |
A String/Constant representing what directions to clamp on. |
buffer | object |
(optional) An Object that has the values to add buffer padding to each side. See properties for more info: |
Properties
Name | Type | Description |
---|---|---|
buffer.left | number |
Amount of left padding |
buffer.right | number |
Amount of right padding |
buffer.top | number |
Amount of top padding |
buffer.bottom | number |
Amount of bottom padding |