Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Created November 10, 2016 11:06
Show Gist options
  • Save nishinoshake/c4c0fd58f508279d9108628d08a99ccc to your computer and use it in GitHub Desktop.
Save nishinoshake/c4c0fd58f508279d9108628d08a99ccc to your computer and use it in GitHub Desktop.
transitionendのJS
/**
* transitionEndのイベント
*
* 使えない場合はsetTimeout
*/
$.fn.extend({
transitionEnd: function() {
var style = document.createElement('div').style;
var canUse = "transition" in style || "WebkitTransition" in style;
var defer = new $.Deferred();
var duration = parseFloat($(this).css('transition-duration')) * 1000;
if ( canUse ) {
$(this).on('transitionend webkitTransitionEnd', function() {
defer.resolve();
});
} else {
setTimeout(function() {
defer.resolve();
}, duration);
}
return defer.promise();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment