Skip to content

Commit

Permalink
Merge pull request madrobby#201 from kossnocorp/200_zero_anim_duratio…
Browse files Browse the repository at this point in the history
…n_bug

Fix "When animation duration is 0 callback never will be called"
  • Loading branch information
madrobby committed Jun 14, 2011
2 parents a8103c7 + 8d9ee92 commit c03bef9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
if (key === 'opacity') opacity = properties[key];
else transforms.push(key + '(' + properties[key] + ')');

$.isFunction(callback) && this.one('webkitTransitionEnd', callback);
if (parseFloat(duration) !== 0) {
$.isFunction(callback) && this.one('webkitTransitionEnd', callback);
} else {
setTimeout(callback, 0);
}

return this.css({
'-webkit-transition': 'all ' + (duration !== undefined ? duration : 0.5) + 's ' + (ease || ''),
Expand Down
14 changes: 14 additions & 0 deletions test/fx.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ <h1>Zepto FX unit tests</h1>
<div id="durationtest_2" style="width:40px;height:40px;background:red"></div>
<div id="callbacktest" style="width:40px;height:40px;background:red"></div>

<div id="anim_zero_duration_callback_test"></div>

<script>
Evidence.TestCase.extend('ZeptoFXTest', {

Expand Down Expand Up @@ -65,6 +67,18 @@ <h1>Zepto FX unit tests</h1>
this.assert((new Date().getTime() - start) >= duration);
});
});

// Test for https://github.com/madrobby/zepto/issues/200
var el = $('#anim_zero_duration_callback_test'),
callbackCalled = false;

el.anim({ opacity: 0.5 }, 0, 'linear', function () {
callbackCalled = true;
});

setTimeout(function () {
t.assert(callbackCalled);
}, 0);
}
});
</script>
Expand Down

0 comments on commit c03bef9

Please sign in to comment.