dimensions插件是一个获得元素尺寸的插件.
height
innerHeight
innerWidth
offset
offsetParent
outerHeight
outerWidth
position
scrollLeft
scrollTop
width
height
扩展了核心的 height
方法 enable it for the window and document objects as well as elements. When used on an element a value can be passed in to set the height. 对可见与不可见的元素都有效
value
A positive number representing the desired height. If just a number, 'px' will be added for you.
$
(window
).height();
$
(document
).height();
$
("#myElement"
).height();
$
("#myElement"
).height(100
);
innerHeight
Gets the inner height (excludes the border and includes the padding) for the first matched element. This method works for both visible and hidden elements.
$
("#myElement"
).innerHeight();
innerWidth
Gets the inner width (excludes the border and includes the padding) for the first matched element. This method works for both visible and hidden elements.
$
("#myElement"
).innerHeight();
offset
Gets the position of an element relative to the viewport. For accurate calculations make sure to use pixel values for margins, borders and padding. This method only works with visible elements.
options
margin
(Boolean)
border
(Boolean)
padding
(Boolean)
scroll
(Boolean)
lite
(Boolean)
relativeTo
(HTML Element)
returnObject
$
("#myElement"
).offset();
{ top: 100
, left: 100
, scrollTop: 10
, scrollLeft: 10
}
$
("#myElement"
).offset({ scroll: false
});
{ top: 100
, left: 100
}
var
offset
= {};
$
("#myElement"
).offset({ scroll: false
}, offset);
offset == { top: 100
, left: 100
}
offsetParent
Returns a jQuery collection with the positioned parent of the first matched element. This is the first parent of the element that has position (as in relative or absolute). This method only works with visible elements.
$
("#myElement"
).offsetParent();
outerHeight
Gets the offsetHeight (includes the border and padding by default) for the first matched element. This method works for both visible and hidden elements. The margin can be included by passing an options map with margin set to true. Optional margin option added in 1.1
options
margin
(Boolean)
$
("#myElement"
).outerHeight();
$
("#myElement"
).outerHeight({ margin: true
});
outerWidth
Gets the offsetWidth (includes the border and padding by default) for the first matched element. This method works for both visible and hidden elements. The margin can be included by passing an options map with margin set to true. Optional margin option added in 1.1
options
margin
(Boolean)
$
("#myElement"
).outerWidth();
$
("#myElement"
).outerWidth({ margin: true
});
position
Gets the top and left position of an element relative to its offset parent. For accurate calculations make sure to use pixel values for margins, borders and padding. This method only works with visible elements.
$
("#myElement"
).position();
{ top: 10
, left: 10
}
var
position
= {};
$
("#myElement"
).position(position);
position == { top: 10
, left: 10
}
scrollLeft
Acts as both a getter and a setter. When no value is passed in, it gets the scroll left offset of the first matched element. When a value is passed in, the scroll left offset is set to that value on all matched elements. This method works for both visible and hidden elements.
value
A positive number representing the desired scroll left offset.
$
("#myElement"
).scrollLeft(100
);
$
("#myElement"
).scrollLeft();
100
scrollTop
Acts as both a getter and a setter. When no value is passed in, it gets the scroll top offset of the first matched element. When a value is passed in, the scroll left offset is set to that value on all matched elements. This method works for both visible and hidden elements.
value
A positive number representing the desired scroll top offset.
$
("#myElement"
).scrollTop(100
);
$
("#myElement"
).scrollTop();
100
width
This is an extension of the core width
method to enable it for the window and document objects as well as elements. When used on an element a value can be passed in to set the width. This method works for both visible and hidden elements.
value
A positive number representing the desired width. If just a number, 'px' will be added for you.
$
(window
).width();
$
(document
).width();
$
("#myElement"
).width();
$
("#myElement"
).width(100
);