Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / docs / source / Element.scroll.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.1
11  * Copyright(c) 2006-2010 Sencha Inc.
12  * licensing@sencha.com
13  * http://www.sencha.com/license
14  */
15 /**
16  * @class Ext.Element
17  */
18 Ext.Element.addMethods({
19     <div id="method-Ext.Element-isScrollable"></div>/**
20      * Returns true if this element is scrollable.
21      * @return {Boolean}
22      */
23     isScrollable : function(){
24         var dom = this.dom;
25         return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
26     },
27
28     <div id="method-Ext.Element-scrollTo"></div>/**
29      * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
30      * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
31      * @param {Number} value The new scroll value.
32      * @return {Element} this
33      */
34     scrollTo : function(side, value){
35         this.dom["scroll" + (/top/i.test(side) ? "Top" : "Left")] = value;
36         return this;
37     },
38
39     <div id="method-Ext.Element-getScroll"></div>/**
40      * Returns the current scroll position of the element.
41      * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
42      */
43     getScroll : function(){
44         var d = this.dom, 
45             doc = document,
46             body = doc.body,
47             docElement = doc.documentElement,
48             l,
49             t,
50             ret;
51
52         if(d == doc || d == body){
53             if(Ext.isIE && Ext.isStrict){
54                 l = docElement.scrollLeft; 
55                 t = docElement.scrollTop;
56             }else{
57                 l = window.pageXOffset;
58                 t = window.pageYOffset;
59             }
60             ret = {left: l || (body ? body.scrollLeft : 0), top: t || (body ? body.scrollTop : 0)};
61         }else{
62             ret = {left: d.scrollLeft, top: d.scrollTop};
63         }
64         return ret;
65     }
66 });</pre>    
67 </body>
68 </html>