Skip to content

Instantly share code, notes, and snippets.

@aurri
Created January 11, 2014 22:24
Show Gist options
  • Save aurri/8377805 to your computer and use it in GitHub Desktop.
Save aurri/8377805 to your computer and use it in GitHub Desktop.
Get transition duration in pure JavaScript, without jQuery
// Based on https://gist.github.com/snorpey/7230329
function getTransitionDuration(el){
var res = 0
prefix('transition-duration', function(v, pfx){
duration = el.style[v]
if(!duration) return
duration = parseTime(duration) + parseTime(el.style[pfx('transition-delay')] || 0)
function parseTime(s){ return parseFloat(s) * (s.indexOf('ms') >- 1 ? 1 : 1000) }
})
return res
function prefix(str, cb, prefixes){
prefixes = ' ' + (prefixes || 'webkit moz ms o khtml')
prefixes.split(' ').some(function(v){
prefix = v ? '-'+v : v
cb(pfx(str), pfx)
function pfx(s){ return camelCase(prefix+s) }
})
function camelCase(s){ return s.toLowerCase().replace(/-(.)/g, function(s, m){ return m.toUpperCase() }) }
}
}
@LeonhWolf
Copy link

instead of el.style use getComputedStyle(el)

Perfect, that's exactly what I was looking for. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment