diff options
author | Trent Richardson <trentdrichardson@gmail.com> | 2014-10-09 16:57:07 -0400 |
---|---|---|
committer | Trent Richardson <trentdrichardson@gmail.com> | 2014-10-09 16:57:07 -0400 |
commit | 0d4dfc3a632116438791c6f3e20c0be889cedfae (patch) | |
tree | 75fb0565e711fbbbfa7ecc98a973d7414e1936da | |
parent | c9b2df3241832f804e100cc6b0fd4b77eb48b4a4 (diff) | |
download | jQuery-Impromptu-0d4dfc3a632116438791c6f3e20c0be889cedfae.zip jQuery-Impromptu-0d4dfc3a632116438791c6f3e20c0be889cedfae.tar.gz jQuery-Impromptu-0d4dfc3a632116438791c6f3e20c0be889cedfae.tar.bz2 |
Frame up animate util
-rw-r--r-- | src/jquery-impromptu.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/jquery-impromptu.js b/src/jquery-impromptu.js index 11729cc..38b5413 100644 --- a/src/jquery-impromptu.js +++ b/src/jquery-impromptu.js @@ -806,6 +806,39 @@ };
/**
+ * animate the collection of elements
+ * @param fromprops object - key/value pairs of css properties to animate from
+ * @param toprops object - key/value pairs of css properties to animate to
+ * @param duration int - milliseconds to animate
+ * @param fn function - callback when done
+ * @return Class - returns this Sel class instance
+ */
+ Sel.prototype.animate = function(fromprops, toprops, duration, fn){
+ var start,
+ raf,
+ progress,
+ percent,
+ animloop = function(time){
+ start = start || time;
+ progress = time - start;
+ percent = progress / duration;
+
+ // do css updates
+ // loop through each from prop and calc the amount to add/subtract
+ // (toprops.width - fromprops.width) * percent
+
+ raf = progress < duration ?
+ window.requestAnimationFrame(animloop) :
+ window.cancelAnimationFrame(raf);
+ },
+ // we need to look for an animation flag so this can be turned off
+ // when needed. Perhaps just set Impromptu.fx = false;
+ fx = imp.fx ? window.requestAnimationFrame(animloop) : this.css(toprops);
+
+ return this;
+ };
+
+ /**
* Sel.serialize - serialize the collection's form fields into an object
* @return Object - keys are field names, values are field values
*/
@@ -938,6 +971,8 @@ return o1;
}
};
+
+ // export the utility class so so we can test it
imp._ = _;
|