Permalink
Browse files

script.aculo.us: added Effect.ScrollTo

git-svn-id: http://svn.rubyonrails.org/rails/spinoffs/scriptaculous@1756 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
madrobby committed Jul 7, 2005
1 parent a896f94 commit c97b2b7c48dbe4c1263cab57991003438722932f
Showing with 507 additions and 0 deletions.
  1. +2 −0 CHANGELOG
  2. +21 −0 src/effects.js
  3. +484 −0 test/effects_scrollto.html
View
@@ -1,5 +1,7 @@
*SVN*
+* Added Effect.ScrollTo to smoothly scroll the page to an element
+
* Better Firefox flickering handling on SlideUp/SlideDown
* Some cleaning up in effects.js
View
@@ -286,6 +286,27 @@ Effect.Highlight.prototype = (new Effect.Base()).extend({
}
});
+Effect.ScrollTo = Class.create();
+Effect.ScrollTo.prototype = (new Effect.Base()).extend({
+ initialize: function(element) {
+ this.element = $(element);
+ Position.prepare();
+ var offsets = Position.cumulativeOffset(this.element);
+ var max = window.innerHeight ?
+ window.height - window.innerHeight :
+ document.body.scrollHeight -
+ (document.documentElement.clientHeight ?
+ document.documentElement.clientHeight : document.body.clientHeight);
+ this.scrollStart = Position.deltaY;
+ this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart;
+ this.start(arguments[1] || {});
+ },
+ update: function(position) {
+ Position.prepare();
+ window.scrollTo(Position.deltaX,
+ this.scrollStart + (position*this.delta));
+ }
+});
/* ------------- prepackaged effects ------------- */
Oops, something went wrong.

0 comments on commit c97b2b7

Please sign in to comment.