简体   繁体   English

未能制作关键帧动画

[英]failed to make keyframes animations

I tried to make a slider with images by css keyframes but it doesn't work with me, here is the code:我试图用 css 关键帧的图像制作 slider 但它对我不起作用,这是代码:

*{
  margin:0;
padding:0;
}

li {
   font-size: 20px;
margin: 10px;
  display : inline-block; } 

a {
   color: black;
   text-decoration: none;   }

a:hover {
    transform: scale(1.05);
}

li:hover {
    transform: scale(1.02);    }

ul li a {
    display: block;
    font-size: 25px;
    color: white ;
         }


.slider {
    min-height: 50vh;
    overflow: hidden;
    width: 100%;
    min-height: 90vh;
    background: url(../images/8.jpg);
    animation: 50s slider infinte;   }
  

  @keyframes slider {
      0% {background: url(../images/2.jpg);}
      25% { background: url(../images/3.jpg);}
     50% {background: url(../images/4.jpg);}
     65% { background: url(../images/5.jpg);}
     85% {background: url(../images/6.jpg);}
   100% {background: url(../images/7.png);}
  }

note that: slider it's a class integred in div tag who is empty after the navbar.请注意: slider 它是一个 class 集成在 div 标签中,在导航栏后为空。

Have you tried using the "background-image" property instead of just "background"?您是否尝试过使用“背景图像”属性而不仅仅是“背景”?

You slider's default background is ../images/8.png but you give it 0% {background: url(../images/2.jpg);} .您滑块的默认背景是../images/8.png但您给它0% {background: url(../images/2.jpg);} Thats might be a problem.那可能是个问题。 I think default value should be same with 0% keyframe我认为默认值应该与 0% 关键帧相同

    .slider {
        min-height: 50vh;
        overflow: hidden;
        width: 100%;
        min-height: 90vh;
        background: url(../images/8.jpg);
        animation: 50s slider infinte;   }
      
    
      @keyframes slider {
          0% {background: url(../images/8.jpg);}
          25% { background: url(../images/3.jpg);}
         50% {background: url(../images/4.jpg);}
         65% { background: url(../images/5.jpg);}
         85% {background: url(../images/6.jpg);}
       100% {background: url(../images/7.png);}
      }

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

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