From c0089481b3b2747a24604cc6cd39e2a6c7c07909 Mon Sep 17 00:00:00 2001 From: mnmly Date: Mon, 15 Jul 2013 07:09:00 -0700 Subject: [PATCH 1/3] Add delay --- Readme.md | 5 +++++ examples/array.html | 3 ++- examples/circle.html | 3 ++- index.js | 21 +++++++++++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index 13ce8dd..f29c7a5 100644 --- a/Readme.md +++ b/Readme.md @@ -17,6 +17,7 @@ var button = document.querySelector('button'); var tween = Tween({ rotate: 0, opacity: 0 }) .ease('out-bounce') .to({ rotate: 360, opacity: 1 }) + .delay(200) .duration(800); tween.update(function(o){ @@ -56,6 +57,10 @@ animate(); Set duration to `ms` [500]. +### Tween#delay(ms:Number) + + Set delay to `ms` [0]. + ### Tween#ease(fn:String|Function) Set easing function to `fn`. diff --git a/examples/array.html b/examples/array.html index e304f6e..25bba04 100644 --- a/examples/array.html +++ b/examples/array.html @@ -25,6 +25,7 @@ var tween = Tween(random(1000, 50)) .ease('out-bounce') .to(random(1000, 400)) + .delay(1000) .duration(800); tween.update(function(a){ @@ -45,4 +46,4 @@ } animate(); - \ No newline at end of file + diff --git a/examples/circle.html b/examples/circle.html index 64e50e5..e563437 100644 --- a/examples/circle.html +++ b/examples/circle.html @@ -20,7 +20,8 @@ var tween = Tween({ alpha: 0, border: 1, radius: 1 }) .ease('out-bounce') .to({ alpha: 1, border: 15, radius: 150 }) - .duration(1000); + .duration(1000) + .delay(1000) tween.update(function(o){ canvas.width = canvas.width; diff --git a/index.js b/index.js index e087722..1d7dcaf 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,7 @@ function Tween(obj) { this._from = obj; this.ease('linear'); this.duration(500); + this.delay(0); } /** @@ -75,6 +76,19 @@ Tween.prototype.duration = function(ms){ return this; }; +/** + * Set delay to `ms` [0]. + * + * @param {Number} ms + * @return {Tween} self + * @api public + */ + +Tween.prototype.delay = function(ms){ + this._delay = ms; + return this; +}; + /** * Set easing function to `fn`. * @@ -121,7 +135,10 @@ Tween.prototype.step = function(){ var duration = this._duration; var now = Date.now(); var delta = now - this._start; - var done = delta >= duration; + var done = delta >= duration + this._delay; + var waiting = delta < this._delay; + + if (waiting) return; // complete if (done) { @@ -137,7 +154,7 @@ Tween.prototype.step = function(){ var to = this._to; var curr = this._curr; var fn = this._ease; - var p = (now - this._start) / duration; + var p = (now - this._start - this._delay) / duration; var n = fn(p); // array From 452342ca4e35d7d5464a0afc15583753c4dd9202 Mon Sep 17 00:00:00 2001 From: mnmly Date: Mon, 16 Jun 2014 06:49:27 -0700 Subject: [PATCH 2/3] Add delay example --- examples/delay.html | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/delay.html diff --git a/examples/delay.html b/examples/delay.html new file mode 100644 index 0000000..79b71b5 --- /dev/null +++ b/examples/delay.html @@ -0,0 +1,43 @@ + + + + + + + From d1bd026cff773c1ec0954dd3e496ddde06cbf6bd Mon Sep 17 00:00:00 2001 From: mnmly Date: Mon, 16 Jun 2014 11:19:42 -0700 Subject: [PATCH 3/3] Revert line from example --- examples/array.html | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/array.html b/examples/array.html index 25bba04..c0ff6e1 100644 --- a/examples/array.html +++ b/examples/array.html @@ -25,7 +25,6 @@ var tween = Tween(random(1000, 50)) .ease('out-bounce') .to(random(1000, 400)) - .delay(1000) .duration(800); tween.update(function(a){