Run CSS3 animation only once (at page loading)

后端 未结 7 1553
面向向阳花
面向向阳花 2020-12-04 19:11

I\'m making a simple landing page driven by CSS3. To make it look awesome there\'s an plopping up:

@keyframes splash {
    from {
             


        
相关标签:
7条回答
  • 2020-12-04 19:32

    After hours of googling: No, it's not possible without JavaScript. The animation-iteration-count: 1; is internally saved in the animation shothand attribute, which gets resetted and overwritten on :hover. When we blur the <a> and release the :hover the old class reapplies and therefore again resets the animation attribute.

    There sadly is no way to save a certain attribute states across element states.

    You'll have to use JavaScript.

    0 讨论(0)
  • 2020-12-04 19:33

    If I understand correctly that you want to play the animation on A only once youu have to add

    animation-iteration-count: 1
    

    to the style for the a.

    0 讨论(0)
  • 2020-12-04 19:37

    For above query apply below css for a

    animation-iteration-count: 1
    
    0 讨论(0)
  • 2020-12-04 19:37

    The following code without "iteration-count: 1" was resulting in all line items pulsing after entering, until the last item loaded, even though 'pulse was not being used.

    <li class="animated slideInLeft delay-1s animation-iteration-count: 1"><i class="fa fa-credit-card" aria-hidden="true"></i> 1111</li>
    
    
    <li class="animated slideInRight delay-1-5s animation-iteration-count: 1"><i class="fa fa-university" aria-hidden="true"></i> 222222</li>
    
    <li class="animated lightSpeedIn delay-2s animation-iteration-count: 1"><i class="fa fa-industry" aria-hidden="true"></i> aaaaaa</li>
    
    <li class="animated slideInLeft delay-2-5s animation-iteration-count: 1"><i class="fa fa-key" aria-hidden="true"></i> bbbbb</li>
    
    <li class="animated slideInRight delay-3s animation-iteration-count: 1"><i class="fa fa-thumbs-up" aria-hidden="true"></i> ccccc</li>
    
    0 讨论(0)
  • 2020-12-04 19:42

    It can be done with a little bit of extra overhead.

    Simply wrap your link in a div, and separate the animation.

    the html ..

    <div class="animateOnce">
        <a class="animateOnHover">me!</a>
    </div>
    

    .. and the css ..

    .animateOnce {
        animation: splash 1s normal forwards ease-in-out;
    }
    
    .animateOnHover:hover {
        animation: hover 1s infinite alternate ease-in-out;
    }
    
    0 讨论(0)
  • 2020-12-04 19:53

    I just got this working on Firefox and Chrome. You just add/remove the below class accordingly to your needs.

    .animateOnce {
      -webkit-animation: NAME-OF-YOUR-ANIMATION 0.5s normal forwards; 
      -moz-animation:    NAME-OF-YOUR-ANIMATION 0.5s normal forwards;
      -o-animation:      NAME-OF-YOUR-ANIMATION 0.5s normal forwards;
    }
    
    0 讨论(0)
提交回复
热议问题