Created
December 21, 2009 04:25
-
-
Save cheeaun/260770 to your computer and use it in GitHub Desktop.
Fx.Morph with per-property transitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Fx.Morph.implement({ | |
| step: function(){ | |
| var time = $time(); | |
| if (time < this.time + this.options.duration){ | |
| var delta = {}; | |
| var d = (time - this.time) / this.options.duration; | |
| var t = this.transition(d); | |
| for (p in this.from){ | |
| var trans = this.transitions[p]; | |
| delta[p] = (trans) ? trans(d) : t; | |
| } | |
| this.set(this.compute(this.from, this.to, delta)); | |
| } else { | |
| this.set(this.compute(this.from, this.to, 1)); | |
| this.complete(); | |
| } | |
| }, | |
| compute: function(from, to, delta, time){ | |
| var now = {}; | |
| for (var p in from){ | |
| now[p] = this.parent(from[p], to[p], delta[p]); | |
| } | |
| return now; | |
| }, | |
| start: function(properties, transitions){ | |
| if (!this.check(properties, transitions)) return this; | |
| if (typeof properties == 'string') properties = this.search(properties); | |
| var from = {}, to = {}; | |
| for (var p in properties){ | |
| var parsed = this.prepare(this.element, p, properties[p]); | |
| from[p] = parsed.from; | |
| to[p] = parsed.to; | |
| } | |
| this.transitions = transitions || {}; | |
| return this.parent(from, to); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment