Mercurial > MadButterfly
comparison nodejs/animate.js @ 831:904b6928f727
Add animation.alpha
author | wycc |
---|---|
date | Wed, 15 Sep 2010 01:19:20 +0800 |
parents | 586e50f82c1f |
children | 3c48a77b75d3 |
comparison
equal
deleted
inserted
replaced
830:2a73ff24c141 | 831:904b6928f727 |
---|---|
207 this._app.refresh(); | 207 this._app.refresh(); |
208 } | 208 } |
209 }; | 209 }; |
210 | 210 |
211 exports.holder = holder; | 211 exports.holder = holder; |
212 | |
213 | |
214 | |
215 function alpha_draw() { | |
216 | |
217 if (this.end == 1) return; | |
218 var percent = (Date.now() - this.starttime)/this.duration; | |
219 if (percent > 1) percent = 1; | |
220 var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha; | |
221 sys.puts("opacity="+sx); | |
222 this.obj.opacity=sx; | |
223 | |
224 this.app.refresh(); | |
225 var self = this; | |
226 if (percent < 1) { | |
227 this.obj.timer=setTimeout(function() { self.draw();}, 20); | |
228 return; | |
229 } | |
230 this.app.refresh(); | |
231 this.obj.animated_alpha = null; | |
232 } | |
233 | |
234 function alpha(app,obj,alpha, duration) { | |
235 try { | |
236 if (obj.animated_alpha) { | |
237 obj.animated_alpha.end = 1; | |
238 } | |
239 } catch(e) { | |
240 | |
241 } | |
242 obj.animated_alpha = this; | |
243 this.app = app; | |
244 this.obj = obj; | |
245 this.end = 0; | |
246 this.starttime = Date.now(); | |
247 this.startalpha = obj.opacity; | |
248 this.targetalpha = alpha; | |
249 this.duration = duration*1000; | |
250 } | |
251 | |
252 alpha.prototype.start = alpha_draw; | |
253 alpha.prototype.draw = alpha_draw; | |
254 exports.alpha = alpha; |