Skip to content

Commit

Permalink
Added Effect.Fade which smoothly turns opacity from 100 to 0 and then…
Browse files Browse the repository at this point in the history
… hides the element #960 [thomas@fesch.at]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1032 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 28, 2005
1 parent b14e5d8 commit b0c0c9c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *SVN*


* Added Effect.Fade which smoothly turns opacity from 100 to 0 and then hides the element #960 [thomas@fesch.at]

* Fixed problem with page caching #958 [Rick Olson] * Fixed problem with page caching #958 [Rick Olson]




Expand Down
30 changes: 30 additions & 0 deletions actionpack/lib/action_view/helpers/javascripts/prototype.js
Expand Up @@ -452,3 +452,33 @@ Effect.Highlight.prototype = {
element.style.backgroundColor = "#ffff" + current.toColorPart(); element.style.backgroundColor = "#ffff" + current.toColorPart();
} }
} }


Effect.Fade = Class.create();
Effect.Fade.prototype = {
initialize: function(element) {
this.element = $(element);
this.start = 100;
this.finish = 0;
this.current = this.start;
this.fade();
},

fade: function() {
if (this.isFinished()) { this.element.style.display = 'none'; return; }
if (this.timer) clearTimeout(this.timer);
this.setOpacity(this.element, this.current);
this.current -= 10;
this.timer = setTimeout(this.fade.bind(this), 100);
},

isFinished: function() {
return this.current <= this.finish;
},

setOpacity: function(element, opacity) {
opacity = (opacity == 100) ? 99.999 : opacity;
element.style.filter = "alpha(opacity:"+opacity+")";
element.style.opacity = opacity/100;
}
}
30 changes: 30 additions & 0 deletions railties/html/javascripts/prototype.js
Expand Up @@ -452,3 +452,33 @@ Effect.Highlight.prototype = {
element.style.backgroundColor = "#ffff" + current.toColorPart(); element.style.backgroundColor = "#ffff" + current.toColorPart();
} }
} }


Effect.Fade = Class.create();
Effect.Fade.prototype = {
initialize: function(element) {
this.element = $(element);
this.start = 100;
this.finish = 0;
this.current = this.start;
this.fade();
},

fade: function() {
if (this.isFinished()) { this.element.style.display = 'none'; return; }
if (this.timer) clearTimeout(this.timer);
this.setOpacity(this.element, this.current);
this.current -= 10;
this.timer = setTimeout(this.fade.bind(this), 100);
},

isFinished: function() {
return this.current <= this.finish;
},

setOpacity: function(element, opacity) {
opacity = (opacity == 100) ? 99.999 : opacity;
element.style.filter = "alpha(opacity:"+opacity+")";
element.style.opacity = opacity/100;
}
}

0 comments on commit b0c0c9c

Please sign in to comment.