Animal
2 Apr 2007, 5:27 AM
As requested by some posters, and extension of the scrollTo functionality to match scrollBy. So now, to animate to the end, rather than calculating the scrollTop yourself, you can do:
myElement.scrollTo("b", 0, true)
The new code:
/**
* Scrolls this element to the specified pixel position from the specified edge.
* @param {String} edge: "left"/"l", or "right"/"r", or "top"/"t", or "bottom"/"b"
* @param {Number} position The new scroll value from the specified edge.
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Element} this
*/
scrollTo : function(edge, position, animate){
var edge = edge.toLowerCase();
var scrollMax, prop;
switch (edge) {
case "l":
case "left":
scrollMax = this.dom.scrollWidth - this.dom.clientWidth;
prop = "scrollLeft";
break;
case "r":
case "right":
scrollMax = this.dom.scrollWidth - this.dom.clientWidth;
prop = "scrollLeft";
position = this.dom.scrollWidth - (position + this.dom.clientWidth);
break;
case "t":
case "top":
scrollMax = this.dom.scrollHeight - this.dom.clientHeight;
prop = "scrollTop";
break;
case "b":
case "bottom":
prop = "scrollTop";
position = this.dom.scrollHeight - (position + this.dom.clientHeight);
break;
}
if (position < 0) position = 0; else if (position > scrollMax) position = scrollMax;
if(!animate || !A){
this.dom[prop] = position;
}else{
var to = prop == "scrollLeft" ? [position, this.dom.scrollTop] : [this.dom.scrollLeft, position];
this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
}
return this;
};
Can we add this to the main branch?
myElement.scrollTo("b", 0, true)
The new code:
/**
* Scrolls this element to the specified pixel position from the specified edge.
* @param {String} edge: "left"/"l", or "right"/"r", or "top"/"t", or "bottom"/"b"
* @param {Number} position The new scroll value from the specified edge.
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Element} this
*/
scrollTo : function(edge, position, animate){
var edge = edge.toLowerCase();
var scrollMax, prop;
switch (edge) {
case "l":
case "left":
scrollMax = this.dom.scrollWidth - this.dom.clientWidth;
prop = "scrollLeft";
break;
case "r":
case "right":
scrollMax = this.dom.scrollWidth - this.dom.clientWidth;
prop = "scrollLeft";
position = this.dom.scrollWidth - (position + this.dom.clientWidth);
break;
case "t":
case "top":
scrollMax = this.dom.scrollHeight - this.dom.clientHeight;
prop = "scrollTop";
break;
case "b":
case "bottom":
prop = "scrollTop";
position = this.dom.scrollHeight - (position + this.dom.clientHeight);
break;
}
if (position < 0) position = 0; else if (position > scrollMax) position = scrollMax;
if(!animate || !A){
this.dom[prop] = position;
}else{
var to = prop == "scrollLeft" ? [position, this.dom.scrollTop] : [this.dom.scrollLeft, position];
this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
}
return this;
};
Can we add this to the main branch?