Last active
December 10, 2015 12:59
-
-
Save tnajdek/4438286 to your computer and use it in GitHub Desktop.
Simple jQuery plugin to handle transitionend events in a nice, unified, cross-browser-compatible way
This file contains 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
// $().addClass('hasTransition').transitionend(function() { console.log('this will happen once css transition ends'); } | |
define(['jquery'], function ($) { | |
"use strict"; | |
$.fn.transitionend = function(callback) { | |
this.each(function() { | |
var transitionend = false, | |
$this = $(this), | |
cleanup = function() { | |
if(!transitionend) { | |
callback.call($this); | |
transitionend = true; | |
} | |
}, | |
timer = setTimeout(cleanup, 1000); | |
$this.bind('webkitTransitionEnd transitionend msTransitionEnd oTransitionEnd', cleanup); | |
}); | |
}; | |
return $; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment