Last active
November 23, 2023 22:43
-
-
Save O-Zone/7230245 to your computer and use it in GitHub Desktop.
Get the name of the browsers transitionEnd event. After calling this, window.transitionEnd will contain the browser specific name of the transitionEnd event. This is an extract of EvandroLG's transitionEnd snippet, without all support for testing different elements and using cache.
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
(function (window) { | |
var transitions = { | |
'transition': 'transitionend', | |
'WebkitTransition': 'webkitTransitionEnd', | |
'MozTransition': 'transitionend', | |
'OTransition': 'otransitionend' | |
}, | |
elem = document.createElement('div'); | |
for(var t in transitions){ | |
if(typeof elem.style[t] !== 'undefined'){ | |
window.transitionEnd = transitions[t]; | |
break; | |
} | |
} | |
})(window); |
All credit goes to: https://github.com/EvandroLG/transitionEnd/ :)
Hi,
Great script! May I suggest the following changes?
- Remove
MSTransition:msTransitionEnd
as IE10+ supports transitions without the prefix - Place
transition
first in thetransitions
map, if non-prefixed is supported it will break sooner...
(function (window) { var transitions = { 'transition': 'transitionend', 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'otransitionend' }, elem = document.createElement('div'); for(var t in transitions){ if(elem.style[t] !== undefined){ window.transitionEnd = transitions[t]; break; } } })(window);
Thanks @Imignot!
Both valid improvements - I have updated the gist! :-)
Perhaps also consider:
if (typeof elem.style[t] !== 'undefined') {
....
Just in case undefined was overwrote.
Thank you @ossreleasefeed - hereby updated! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Known Bug: For some reason IE10 returns webkitTransitionEnd, which is wrong. I have no problem with that in my usecase (and am in a hurry), so I'll just leave it as is.