Possible to reverse a css animation on class removal?

前端 未结 6 1046
傲寒
傲寒 2021-02-02 05:03

Essentially what I\'m trying to do is give an element a CSS animation when it gains a class, then reverse that animation when I remove the class without playing the anim

6条回答
  •  情书的邮戳
    2021-02-02 05:47

    Another approach, rather than using display: none, is to suppress the reverse animation with a class on page load, and then remove that class with the same event that applies the normal animation (eg: flipper). Like so (http://jsfiddle.net/astrotim/d7omcbrz/1/):

    CSS - in addition to the flipperUp keyframe posted by Blake above

    #item.no-animation 
    {
      animation: none;
    }
    

    jQuery

    $('#trigger').on({
        mouseenter: function(){
            $('#item').removeClass('no-animation');
            $('#item').addClass('flipped');
        },
        mouseleave: function(){
            $('#item').removeClass('flipped');
        }
    })
    

提交回复
热议问题