【问题标题】:Infinitely sliding CSS3 gradient无限滑动CSS3渐变
【发布时间】:2015-09-26 23:20:21
【问题描述】:

我有一个对角线来回跳动的简单动画,我希望它无休止地滑动而不是来回跳动。这是我的代码:

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>

我尝试删除 50% 的关键帧,但这只是让整个事情跳回到最后一个关键帧的开头。有任何想法吗?

【问题讨论】:

标签: css css-animations


【解决方案1】:

问题是你的渐变。对于无限循环,您应该有四种颜色:

我已在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%);

【讨论】:

  • 非常感谢,这完全解决了我的问题。有没有办法去除每一站的丑陋条纹?
  • 你是指那些锐利的色标吗?让你的背景更大
  • 哦,我应该提一下,如果你把它变大,你应该修复关键帧吗?我的意思是 15% 100% 应该改变
  • 是的,我在缩放背景时立即注意到它开始跳跃,我数学不好,我应该如何修复关键帧?
  • 我不知道。我应该测试一下。你的背景尺寸是多少?
猜你喜欢
  • 2019-08-24
  • 1970-01-01
  • 2013-10-24
  • 2012-08-31
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-03
相关资源
最近更新 更多