if (typeof String.trim == 'undefined') { String.prototype.trim = function () { return this.replace (/^\s+|\s+$/g, ''); }; } function Transition (e) { var prop = e.style.transitionProperty.split (','); var dur = e.style.transitionDuration.split (','); this.e = e; // assert (true, (prop.length == dur.length)); for (var i = 0; i < prop.length; i++) this[prop[i].trim ()] = dur[i].trim (); return this; } Transition.prototype = { getProperties: function () { var names = []; for (var p in this) if (typeof this[p] == 'string') names.push (p); return names; }, applyTransitions: function (o) { var names = this.getProperties (); this.e.style.transitionProperty = names.join (', '); var dur = []; for (var n in names) dur.push (this[names[n]]); this.e.style.transitionDuration = dur.join (', '); if (typeof o == 'object') // ({width: '50px', height: '200px'}) for (var p in o) this.e.style[p] = o[p]; } };