Infinitely sliding CSS3 gradient

不打扰是莪最后的温柔 提交于 2019-12-11 10:18:26

问题


I have this simple animation that pulses back and forth diagonally, I would like it to slide endlessly instead of pulsing back and forth. Here is my code:

body {margin: 0; padding: 0;}

.error-con {
    background: rgba(255, 0, 89, 1);
    background: -moz-linear-gradient(45deg, rgba(255, 0, 89, 1) 0%, rgba(0, 179, 255, 1) 100%);
    background: -webkit-gradient(left bottom, right top, color-stop(0%, rgba(255, 0, 89, 1)), color-stop(100%, rgba(0, 179, 255, 1)));
    background: -webkit-linear-gradient(45deg, rgba(255, 0, 89, 1) 0%, rgba(0, 179, 255, 1) 100%);
    background: -o-linear-gradient(45deg, rgba(255, 0, 89, 1) 0%, rgba(0, 179, 255, 1) 100%);
    background: -ms-linear-gradient(45deg, rgba(255, 0, 89, 1) 0%, rgba(0, 179, 255, 1) 100%);
    background: linear-gradient(45deg, rgba(255, 0, 89, 1) 0%, rgba(0, 179, 255, 1) 100%);
    background-size: 400% 400%;
    -webkit-animation: errorBg 55s ease infinite;
    -moz-animation: errorBg 55s ease infinite;
    animation: errorBg 55s ease infinite;
    height: 100vh;
}

@-webkit-keyframes errorBg {
    0% {
        background-position: 93% 0%
    }
    50% {
        background-position: 0% 100%
    }
    100% {
        background-position: 93% 0%
    }
}

@-moz-keyframes errorBg {
    0% {
        background-position: 93% 0%
    }
    50% {
        background-position: 0% 100%
    }
    100% {
        background-position: 93% 0%
    }
}

@keyframes errorBg {
    0% {
        background-position: 93% 0%
    }
    50% {
        background-position: 0% 100%
    }
    100% {
        background-position: 93% 0%
    }
}
<div class="error-con"></div>

I tried removing the 50% keyframe but that just made the whole thing jump back to the start at the last keyframe. Any ideas?


回答1:


The problem is your gradient. For an infinite loop you should have four colors:

I've Fixed Your Code In This Fiddle

background: -webkit-linear-gradient(45deg, rgba(255, 0, 89, 1) 0%, rgba(0, 179, 255, 1) 33%, rgba(255, 0, 89, 1) 66%, rgba(0, 179, 255, 1) 100%);


来源:https://stackoverflow.com/questions/31302983/infinitely-sliding-css3-gradient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!