diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-28 10:22:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-28 10:22:44 +0000 |
commit | b0c0c9c2ef908606c03e03c7db422fde703eaa99 (patch) | |
tree | 9324906f08b575b0e1dd27f6c4694a22dd52849d /railties | |
parent | b14e5d8334ac5c46d69c1eee4fcb2f3a73da3e6a (diff) | |
download | rails-b0c0c9c2ef908606c03e03c7db422fde703eaa99.tar.gz rails-b0c0c9c2ef908606c03e03c7db422fde703eaa99.tar.bz2 rails-b0c0c9c2ef908606c03e03c7db422fde703eaa99.zip |
Added Effect.Fade which smoothly turns opacity from 100 to 0 and then hides the element #960 [thomas@fesch.at]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1032 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r-- | railties/html/javascripts/prototype.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js index 5042e3304d..2541866ccb 100644 --- a/railties/html/javascripts/prototype.js +++ b/railties/html/javascripts/prototype.js @@ -452,3 +452,33 @@ Effect.Highlight.prototype = { 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; + } +}
\ No newline at end of file |