Skip to content

Instantly share code, notes, and snippets.

@matori
Last active August 29, 2015 14:16
Show Gist options
  • Save matori/81e65875dc36d3ca181b to your computer and use it in GitHub Desktop.
Save matori/81e65875dc36d3ca181b to your computer and use it in GitHub Desktop.
transitoinend と animation* を判定する
'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()
'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