Created
November 10, 2016 11:06
-
-
Save nishinoshake/c4c0fd58f508279d9108628d08a99ccc to your computer and use it in GitHub Desktop.
transitionendのJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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