Created
January 11, 2014 22:24
-
-
Save aurri/8377805 to your computer and use it in GitHub Desktop.
Get transition duration in pure JavaScript, without jQuery
This file contains 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
// 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() }) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect, that's exactly what I was looking for. Thank you!