3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
10 Ext.Element.addMethods({
12 * 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().
13 * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
14 * @param {Number} value The new scroll value
15 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
16 * @return {Element} this
18 scrollTo : function(side, value, animate){
19 var top = /top/i.test(side), //check if we're scrolling top or left
23 if (!animate || !me.anim) {
24 prop = 'scroll' + (top ? 'Top' : 'Left'), // just setting the value, so grab the direction
27 prop = 'scroll' + (top ? 'Left' : 'Top'), // if scrolling top, we need to grab scrollLeft, if left, scrollTop
28 me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}},
29 me.preanim(arguments, 2), 'scroll');
35 * Scrolls this element into view within the passed container.
36 * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a
37 * string (id), dom node, or Ext.Element.
38 * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
39 * @return {Ext.Element} this
41 scrollIntoView : function(container, hscroll){
42 var c = Ext.getDom(container) || Ext.getBody().dom,
44 o = this.getOffsetsTo(c),
45 l = o[0] + c.scrollLeft,
46 t = o[1] + c.scrollTop,
47 b = t + el.offsetHeight,
48 r = l + el.offsetWidth,
50 ct = parseInt(c.scrollTop, 10),
51 cl = parseInt(c.scrollLeft, 10),
53 cr = cl + c.clientWidth;
55 if (el.offsetHeight > ch || t < ct) {
60 c.scrollTop = c.scrollTop; // corrects IE, other browsers will ignore
62 if(hscroll !== false){
63 if(el.offsetWidth > c.clientWidth || l < cl){
66 c.scrollLeft = r - c.clientWidth;
68 c.scrollLeft = c.scrollLeft;
74 scrollChildIntoView : function(child, hscroll){
75 Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
79 * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
80 * within this element's scrollable range.
81 * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
82 * @param {Number} distance How far to scroll the element in pixels
83 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
84 * @return {Boolean} Returns true if a scroll was triggered or false if the element
85 * was scrolled as far as it could go.
87 scroll : function(direction, distance, animate){
88 if(!this.isScrollable()){
92 l = el.scrollLeft, t = el.scrollTop,
93 w = el.scrollWidth, h = el.scrollHeight,
94 cw = el.clientWidth, ch = el.clientHeight,
97 l: Math.min(l + distance, w-cw),
98 r: v = Math.max(l - distance, 0),
99 t: Math.max(t - distance, 0),
100 b: Math.min(t + distance, h-ch)
105 direction = direction.substr(0, 1);
106 if((v = hash[direction]) > -1){
108 this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));