ccurtin
2/27/2017 - 12:41 AM

returns prefixed transition and animation events for use in javascript. Checks if Animation exists first, then custom type. ex: element.addE

returns prefixed transition and animation events for use in javascript. Checks if Animation exists first, then custom type. ex: element.addEventListener(browserSpecificEventNames("AnimationStart"),function(){console.log("testing")}, false)

function browserSpecificEventNames(type) {
    // create test element
    var elm = document.createElement('div'),
        match = {},
        list = {
            'WebkitAnimation': 'webkit' + type,
            'MozAnimation': 'moz' + type,
            'OAnimation': 'o' + type,
            'msAnimation': 'MS' + type,
            'animation': type,
        }
    for (var i in list) {
        if (list.hasOwnProperty(i) && elm.style[i] !== undefined) {
            return list[i]
        }
    }
    return match
}