CSS3 animation - smooth infinite cycle

前端 未结 2 1839
后悔当初
后悔当初 2020-12-29 13:17

I\'ve made a small background animation where a div changes color over time. It works smoothly, but when it gets to 100% it jumps straight to 0% without any transition. I\'v

2条回答
  •  灰色年华
    2020-12-29 13:36

    You just have to fix your frames in another way : make the from (0%) and to (100%) values the same:

    html, body {   
        width: 100%; height: 100%;
        margin: 0;
        padding: 0;
    }
    body {
        -webkit-animation: pulsate 20s linear infinite;
        -moz-animation: pulsate 20s linear infinite;
        animation: pulsate 20s linear infinite;
    }
    
    @-webkit-keyframes pulsate {
        0% {background: black}
        20% {background: red}
        40% {background: blue}
        60% {background: orange}
        80% {background: green}
        100% {background: black}
    }
    @-moz-keyframes pulsate {
        0% {background: black}
        20% {background: red}
        40% {background: blue}
        60% {background: orange}
        80% {background: green}
        100% {background: black}
    }
    @keyframes pulsate {
        0% {background: black}
        20% {background: red}
        40% {background: blue}
        60% {background: orange}
        80% {background: green}
        100% {background: black}
    }

提交回复
热议问题