transitionend event fires twice

后端 未结 6 800
渐次进展
渐次进展 2020-12-04 19:33

I have the following code and my problem is that the transitionend event is fired twice. I don\'t know what\'s causing this. I suspected the vendor prefixes cau

6条回答
  •  甜味超标
    2020-12-04 20:11

    This is a relatively old question but I thought I'd share my answer:

    function OnTransitionEvent() {
        var t,
            el = document.createElement('transitionElement');
    
        var transitions = {
            'transition'      : 'transitionend',
            'OTransition'     : 'oTransitionEnd',
            'MozTransition'   : 'transitionend',
            'WebkitTransition': 'webkitTransitionEnd'
        };
    
        for (t in transitions){
            if (el.style[t] !== undefined){
                return transitions[t];
            }
        }
    }
    
    var transitionEvent = OnTransitionEvent();
    
    $(document).one(transitionEvent, function() { 
        console.log('done');
    });
    

提交回复
热议问题