Skip to content

Latest commit

 

History

History
86 lines (67 loc) · 2.69 KB

Clamp.md

File metadata and controls

86 lines (67 loc) · 2.69 KB

Clamp

Kind: global class
Npmpackage:

new Clamp()

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
});

Clamp.X : string

Synonymous with "clampX" - clamp on the horizontal direction only

Kind: static constant of Clamp

Clamp.Y : string

Synonymous with "clampY" - clamp on the vertical direction only

Kind: static constant of Clamp

Clamp.XY : string

Synonymous with "clampXY" - clamp on all sides

Kind: static constant of Clamp

Clamp.set(source, type, buffer)

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