2 * This plugin overrides jQuery's height() and width() functions and
\r
3 * adds more handy stuff for cross-browser compatibility.
\r
7 * Returns the css height value for the first matched element.
\r
8 * If used on document, returns the document's height (innerHeight)
\r
9 * If used on window, returns the viewport's (window) height
\r
11 * @example $("#testdiv").height()
\r
14 * @example $(document).height();
17 * @example $(window).height();
24 $.fn.height = function() {
\r
25 if ( this.get(0) == window )
26 return self.innerHeight ||
27 jQuery.boxModel && document.documentElement.clientHeight ||
\r
28 document.body.clientHeight;
\r
30 if ( this.get(0) == document )
\r
31 return Math.max( document.body.scrollHeight, document.body.offsetHeight );
\r
33 return this.css("height");
\r
37 * Returns the css width value for the first matched element.
\r
38 * If used on document, returns the document's width (innerWidth)
\r
39 * If used on window, returns the viewport's (window) width
\r
41 * @example $("#testdiv").width()
\r
44 * @example $(document).width();
47 * @example $(window).width();
54 $.fn.width = function() {
\r
55 if ( this.get(0) == window )
56 return self.innerWidth ||
57 jQuery.boxModel && document.documentElement.clientWidth ||
\r
58 document.body.clientWidth;
\r
60 if ( this.get(0) == document )
\r
61 return Math.max( document.body.scrollWidth, document.body.offsetWidth );
\r
63 return this.css("width");
\r
67 * Returns the inner height value (without border) for the first matched element.
\r
68 * If used on document, returns the document's height (innerHeight)
\r
69 * If used on window, returns the viewport's (window) height
\r
71 * @example $("#testdiv").innerHeight()
\r
78 $.fn.innerHeight = function() {
\r
79 return this.get(0) == window || this.get(0) == document ?
81 this.get(0).offsetHeight - parseInt(this.css("borderTop")) - parseInt(this.css("borderBottom"));
\r
85 * Returns the inner width value (without border) for the first matched element.
\r
86 * If used on document, returns the document's Width (innerWidth)
\r
87 * If used on window, returns the viewport's (window) width
\r
89 * @example $("#testdiv").innerWidth()
\r
96 $.fn.innerWidth = function() {
\r
97 return this.get(0) == window || this.get(0) == document ?
99 this.get(0).offsetWidth - parseInt(this.css("borderLeft")) - parseInt(this.css("borderRight"));
\r
103 * Returns the outer height value (including border) for the first matched element.
\r
104 * Cannot be used on document or window.
\r
106 * @example $("#testdiv").outerHeight()
\r
109 * @name outerHeight
\r
113 $.fn.outerHeight = function() {
\r
114 return this.get(0) == window || this.get(0) == document ?
116 this.get(0).offsetHeight;
\r
120 * Returns the outer width value (including border) for the first matched element.
\r
121 * Cannot be used on document or window.
\r
123 * @example $("#testdiv").outerWidth()
\r
130 $.fn.outerWidth = function() {
\r
131 return this.get(0) == window || this.get(0) == document ?
133 this.get(0).offsetWidth;
\r
137 * Returns how many pixels the user has scrolled to the right (scrollLeft).
\r
138 * Works on containers with overflow: auto and window/document.
\r
140 * @example $("#testdiv").scrollLeft()
\r
147 $.fn.scrollLeft = function() {
\r
148 if ( this.get(0) == window || this.get(0) == document )
149 return self.pageXOffset ||
150 jQuery.boxModel && document.documentElement.scrollLeft ||
151 document.body.scrollLeft;
153 return this.get(0).scrollLeft;
\r
157 * Returns how many pixels the user has scrolled to the bottom (scrollTop).
\r
158 * Works on containers with overflow: auto and window/document.
\r
160 * @example $("#testdiv").scrollTop()
\r
167 $.fn.scrollTop = function() {
\r
168 if ( this.get(0) == window || this.get(0) == document )
169 return self.pageYOffset ||
170 jQuery.boxModel && document.documentElement.scrollTop ||
171 document.body.scrollTop;
173 return this.get(0).scrollTop;
\r