Mercurial > MadButterfly
diff nodejs/animate.js @ 831:904b6928f727
Add animation.alpha
author | wycc |
---|---|
date | Wed, 15 Sep 2010 01:19:20 +0800 |
parents | 586e50f82c1f |
children | 3c48a77b75d3 |
line wrap: on
line diff
--- a/nodejs/animate.js Wed Sep 15 01:18:49 2010 +0800 +++ b/nodejs/animate.js Wed Sep 15 01:19:20 2010 +0800 @@ -209,3 +209,46 @@ }; exports.holder = holder; + + + +function alpha_draw() { + + if (this.end == 1) return; + var percent = (Date.now() - this.starttime)/this.duration; + if (percent > 1) percent = 1; + var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha; + sys.puts("opacity="+sx); + this.obj.opacity=sx; + + this.app.refresh(); + var self = this; + if (percent < 1) { + this.obj.timer=setTimeout(function() { self.draw();}, 20); + return; + } + this.app.refresh(); + this.obj.animated_alpha = null; +} + +function alpha(app,obj,alpha, duration) { + try { + if (obj.animated_alpha) { + obj.animated_alpha.end = 1; + } + } catch(e) { + + } + obj.animated_alpha = this; + this.app = app; + this.obj = obj; + this.end = 0; + this.starttime = Date.now(); + this.startalpha = obj.opacity; + this.targetalpha = alpha; + this.duration = duration*1000; +} + +alpha.prototype.start = alpha_draw; +alpha.prototype.draw = alpha_draw; +exports.alpha = alpha;