Last active
August 29, 2015 14:16
-
-
Save matori/81e65875dc36d3ca181b to your computer and use it in GitHub Desktop.
transitoinend と animation* を判定する
This file contains hidden or 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
'use strict' | |
el = document.createElement 'div' | |
detectionTargets = | |
transitionend: | |
'WebkitTransition': 'webkitTransitionEnd' | |
'transition': 'transitionend' | |
animationend: | |
'WebkitAnimation': 'webkitAnimationEnd' | |
'animation': 'animationend' | |
normalize = (obj) -> | |
for styleProp of obj | |
if obj.hasOwnProperty styleProp | |
if el.style[styleProp] != undefined | |
return obj[styleProp] | |
normalizeTransAnimEventName = -> | |
normalized = {} | |
for target of detectionTargets | |
if detectionTargets.hasOwnProperty target | |
normalized[target] = normalize detectionTargets[target] | |
if normalized.hasOwnProperty 'animationend' | |
isWebkitAnim = normalized.animationend == 'webkitAnimationEnd' | |
normalized['animationstart'] = if isWebkitAnim then 'webkitAnimationStart' else 'animationstart' | |
normalized['animationiteration'] = if isWebkitAnim then 'webkitAnimationIteration' else 'animationiteration' | |
el = undefined | |
normalized | |
module.exports = normalizeTransAnimEventName() |
This file contains hidden or 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
'use strict'; | |
var detectionTargets, el, normalize, normalizeTransAnimEventName; | |
el = document.createElement('div'); | |
detectionTargets = { | |
transitionend: { | |
'WebkitTransition': 'webkitTransitionEnd', | |
'transition': 'transitionend' | |
}, | |
animationend: { | |
'WebkitAnimation': 'webkitAnimationEnd', | |
'animation': 'animationend' | |
} | |
}; | |
normalize = function(obj) { | |
var styleProp; | |
for (styleProp in obj) { | |
if (obj.hasOwnProperty(styleProp)) { | |
if (el.style[styleProp] !== void 0) { | |
return obj[styleProp]; | |
} | |
} | |
} | |
}; | |
normalizeTransAnimEventName = function() { | |
var isWebkitAnim, normalized, target; | |
normalized = {}; | |
for (target in detectionTargets) { | |
if (detectionTargets.hasOwnProperty(target)) { | |
normalized[target] = normalize(detectionTargets[target]); | |
} | |
} | |
if (normalized.hasOwnProperty('animationend')) { | |
isWebkitAnim = normalized.animationend === 'webkitAnimationEnd'; | |
normalized['animationstart'] = isWebkitAnim ? 'webkitAnimationStart' : 'animationstart'; | |
normalized['animationiteration'] = isWebkitAnim ? 'webkitAnimationIteration' : 'animationiteration'; | |
} | |
el = void 0; | |
return normalized; | |
}; | |
module.exports = normalizeTransAnimEventName(); | |
// --- | |
// generated by coffee-script 1.9.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment