Skip to content

Instantly share code, notes, and snippets.

@tnajdek
Last active December 10, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnajdek/4438286 to your computer and use it in GitHub Desktop.
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
// $().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