I'm implementing an excellent solution (found here) to use a callback function a la jQuery when using CSS transitions.
The problem is that if I use vendor prefixes, Chrome at least binds two events: one for webkitTransitionEnd and the second one for transitionend and, of course, fires the callback twice. Here's my piece of code:
jQuery("#main").one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) {
console.log("POUM!");
});
Am I doing something wrong?
You're not doing anything wrong. Chrome just uses both the prefixed and un-prefixed versions.
There are a couple options:
Using an outside variable.
Using some kind of detection to get a single variable for transitionend (the below uses Modernizr, and is taken from their documentation):
NOTE:
Safari 6 seems to trigger
onloadfor anything that is set in the CSS. So, if you have (assuming all prefixes)Safari will trigger the
transitionendwithwidthandheighton load. There are a couple ways to get around this:Do the following in javascript (it's not the prettiest thing, but it should take care of that edge case and it still works in Chrome) fiddle