Skip to content

Instantly share code, notes, and snippets.

@magicspon
Last active March 21, 2018 00:27
Show Gist options
  • Save magicspon/350a454853635f73d781e2a59380b884 to your computer and use it in GitHub Desktop.
Save magicspon/350a454853635f73d781e2a59380b884 to your computer and use it in GitHub Desktop.
animation/transition end event prop
export default (type = 'transition') => {
let types =
type === 'transition'
? {
OTransition: 'oTransitionEnd',
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
transition: 'transitionend'
}
: {
OAnimation: 'oAnimationEnd',
WebkitAnimation: 'webkitAnimationEnd',
MozAnimation: 'animationend',
animation: 'animationend'
}
const elem = document.createElement('div')
return Object.keys(types).reduce(function(prev, trans) {
return undefined !== elem.style[trans] ? types[trans] : prev
}, '')
}
import animationEnd from '@/utils/animationEnd'
describe('example', () => {
it('should return animationend when passed the string animation', () => {
const value = animationEnd('animation')
expect(value).toBe('animationend')
})
it('should return transitionend when passed the string transition', () => {
const value = animationEnd('transition')
expect(value).toBe('transitionend')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment