Skip to content

Instantly share code, notes, and snippets.

@axelmichel
Created January 13, 2017 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axelmichel/a47c89f66fa2282dcb1a4b24b72db390 to your computer and use it in GitHub Desktop.
Save axelmichel/a47c89f66fa2282dcb1a4b24b72db390 to your computer and use it in GitHub Desktop.
Extracting the transition with the longest duration (and delay)
function getMaxDurationTransitionProperty(el) {
// small helper to extract the values
function extract(str) {
return str
.replace(/[A-Z]/gi, "")
.split(", ")
.map(parseFloat);
};
// get the current style
var style = getComputedStyle(el);
// get all transition properties
var props = style.transitionProperty.split(", ");
// we need delay and duration
var delays = extract(style.transitionDelay);
var durations = extract(style.transitionDuration);
// combinate delay and duration
var totals = durations.map(function(v, i) {
return v + delays[i];
});
// find the property with longest value
var max = totals[0];
var maxIndex = 0;
for (var i = 1; i < totals.length; i++) {
if (totals[i] > max) {
maxIndex = i;
max = totals[i];
}
}
// and return this property
return props[maxIndex];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment