How to prevent css keyframe animation to run on page load?

后端 未结 7 1875
轻奢々
轻奢々 2020-12-07 20:20

I have a div in which I animate the content:

7条回答
  •  遥遥无期
    2020-12-07 20:53

    I always set preload class to body with animation time value 0 and its working pretty well. I have some back going transitions so I have to remove load animation to them too. I solved this by temporary setting animation time to 0. You can change transitions to match yours.

    HTML

    ... ...

    CSS is setting animation to 0s

    body.preload *{
    animation-duration: 0s !important;
    -webkit-animation-duration: 0s !important;
    transition:background-color 0s, opacity 0s, color 0s, width 0s, height 0s, padding 0s, margin 0s !important;}
    

    JS will remove class after some delay so animations can happen in normal time :)

    setTimeout(function(){
        document.body.className="";
    },500);
    

提交回复
热议问题