简体   繁体   English

css背景自动改变动画

[英]css background automatically changing animation

pretty new to coding so this is probably a very simple problem but everyone starts somewhere you know, dont judge.对编码非常陌生,所以这可能是一个非常简单的问题,但每个人都从你知道的地方开始,不要判断。

im trying to make an automatically changing background.我正在尝试制作自动更改的背景。 I'm aware that i dont have the animation attributes / percentages done correctly.. i am currently messing around with it !我知道我没有正确完成动画属性/百分比..我目前正在处理它!

question is as soon as i put a linear-gradient on the animation backgrounds the transition ease was null and void.问题是,一旦我在动画背景上放置线性渐变,过渡缓动就无效了。 Is this always the case or am i doing it wrong ?总是这样还是我做错了? thank you谢谢你

header {
  height: 100vh;
  background: linear-gradient(rgba(0, 0, 0, 0.2)),
    url("./hero.jpeg") center center/cover;
  animation: animate 30s infinite forwards ease;

  @keyframes animate {
    0% {
      background: linear-gradient(rgba(0, 0, 0, 0.2)),
        url(./hero.jpeg) center center/cover;
    }
    20% {
      background: linear-gradient(rgba(0, 0, 0, 0.2)),
        url(./hero2.jpeg) center center/cover;
    }
    40% {
      background: linear-gradient(rgba(0, 0, 0, 0.2)),
        url(./hero3.jpeg) center center/cover;
    }
    60% {
      background: linear-gradient(rgba(0, 0, 0, 0.2)),
        url(./hero4.jpeg) center center/cover;
    }
    80% {
      background: linear-gradient(rgba(0, 0, 0, 0.2)),
        url(./hero5.jpeg) center center/cover;
    }
    100% {
      background: linear-gradient(rgba(0, 0, 0, 0.2)),
        url(./hero.jpeg) center center/cover;
    }
  }
}

The linear gradient should have at least two values, not one, and you shouldn't have a comma separating the two backgrounds.线性渐变应该至少有两个值,而不是一个,并且您不应该用逗号分隔两个背景。 You didn't give me two values, so I just removed the gradient for the transparent color.你没有给我两个值,所以我只是删除了透明颜色的渐变。

Wrong错误的

  background: linear-gradient(rgba(0, 0, 0, 0.2)),
    url(./hero.jpeg) center center/cover;

Correct正确的

  background: rgba(0, 0, 0, 0.2)
    url(./hero.jpeg) center center/cover;

 header { height: 100vh; animation: animate 30s infinite forwards ease; } @keyframes animate { 0% { background: rgba(0, 0, 0, 0.2) url("https://picsum.photos/id/1/200/200") center center/cover; } 20% { background: rgba(0, 0, 0, 0.2) url("https://picsum.photos/id/2/200/200") center center/cover; } 40% { background: rgba(0, 0, 0, 0.2) url("https://picsum.photos/id/3/200/200") center center/cover; } 60% { background: rgba(0, 0, 0, 0.2) url("https://picsum.photos/id/4/200/200") center center/cover; } 80% { background: rgba(0, 0, 0, 0.2) url("https://picsum.photos/id/5/200/200") center center/cover; } 100% { background: rgba(0, 0, 0, 0.2) url("https://picsum.photos/id/1/200/200") center center/cover; } }
 <header></header>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM