2 Script: Element.Dimensions.js
3 Contains Element prototypes to deal with Element size and position in space.
6 The functions in this script require n XHTML doctype.
14 Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
21 Scrolls the element to the specified coordinated (if the element has an overflow)
28 >$('myElement').scrollTo(0, 100)
31 scrollTo: function(x, y){
38 Return an Object representing the size/scroll values of the element.
42 $('myElement').getSize();
48 'scroll': {'x': 100, 'y': 100},
49 'size': {'x': 200, 'y': 400},
50 'scrollSize': {'x': 300, 'y': 500}
57 'scroll': {'x': this.scrollLeft, 'y': this.scrollTop},
58 'size': {'x': this.offsetWidth, 'y': this.offsetHeight},
59 'scrollSize': {'x': this.scrollWidth, 'y': this.scrollHeight}
65 Returns the real offsets of the element.
68 overflown - optional, an array of nested scrolling containers for scroll offset calculation, use this if your element is inside any element containing scrollbars
71 >$('element').getPosition();
77 getPosition: function(overflown){
78 overflown = overflown || [];
79 var el = this, left = 0, top = 0;
81 left += el.offsetLeft || 0;
82 top += el.offsetTop || 0;
85 overflown.each(function(element){
86 left -= element.scrollLeft || 0;
87 top -= element.scrollTop || 0;
89 return {'x': left, 'y': top};
94 Returns the distance from the top of the window to the Element.
97 overflown - optional, an array of nested scrolling containers, see Element::getPosition
100 getTop: function(overflown){
101 return this.getPosition(overflown).y;
106 Returns the distance from the left of the window to the Element.
109 overflown - optional, an array of nested scrolling containers, see Element::getPosition
112 getLeft: function(overflown){
113 return this.getPosition(overflown).x;
117 Property: getCoordinates
118 Returns an object with width, height, left, right, top, and bottom, representing the values of the Element
121 overflown - optional, an array of nested scrolling containers, see Element::getPosition
125 var myValues = $('myElement').getCoordinates();
141 getCoordinates: function(overflown){
142 var position = this.getPosition(overflown);
144 'width': this.offsetWidth,
145 'height': this.offsetHeight,
149 obj.right = obj.left + obj.width;
150 obj.bottom = obj.top + obj.height;