Skip to content

Instantly share code, notes, and snippets.

@csuwildcat
Created October 4, 2013 00:07
Show Gist options
  • Select an option

  • Save csuwildcat/6819046 to your computer and use it in GitHub Desktop.

Select an option

Save csuwildcat/6819046 to your computer and use it in GitHub Desktop.
A custom event that notifies you when all declared transition properties have completed a transition
var replaceSpaces = / /g;
xtag.customEvents.transitionall = {
observe: { transitionend: document },
condition: function(e, tap){
var element = e.target;
if (!element.__transall__ && (element.__tranend__ ? element.__tranend__ > e.elapsedTime : true)) {
delete element.__transtime__;
var trans = element.__transall__ = { duration: 0 };
style = getComputedStyle(element),
props = (style.transitionProperty || style[xtag.prefix.js + 'TransitionProperty']).replace(replaceSpaces, '').split(','),
i = props.length;
trans.props = {};
trans.count = 0;
while (i--) if (!trans.props[props[i]]) {
trans.props[props[i]] = props[i];
trans.count++;
}
}
if (element.__transall__) {
var trans = element.__transall__,
prop = trans.props[e.propertyName] || trans.props[e.propertyName.split('-')[e.propertyName[0] == '-' ? 2 : 0]];
if (prop) {
trans.props[prop] = 0;
trans.count--;
}
if (!trans.count) {
element.__tranend__ = e.elapsedTime;
delete element.__transall__;
return true;
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment