【问题标题】:background animation zoom in and out slideshow in css背景动画在css中放大和缩小幻灯片
【发布时间】:2020-10-13 21:24:02
【问题描述】:

我正在尝试创建动画背景幻灯片,放大第一张图像,然后为下一张图像恢复正常并对其进行缩放,请问有什么想法吗??

    .img-contaner {
     position: fixed;
     width: 100%;
     height: 100%;
     background-size: cover;
     background-position: center;
     animation: img 20s ease-in-out infinite;
     background: url(./1.jpg);  
      }
      @keyframes img{
     25%{
         background: url(./2.jpg);
         transform: scale(1.2); 
     }
     50%{
         background: url(./3.jpg);
         transform: scale(1.2); 
     }
     75%{
         background: url(./4.jpg);
         transform: scale(1.2); 
     }
     100%{
         background: url(./1.jpg); 
        transform: scale(1.2);
    }

     }

我试过了,但图像在整个动画中保持缩放

【问题讨论】:

  • @blex 给你:<div class="img-contaner"></div>

标签: javascript html css user-interface web


【解决方案1】:
  • 不要覆盖使用background: shorthand 的背景图像。您将覆盖其他 background-* 样式。
  • 将所有图片预加载到浏览器中,以防止使用 :before 伪图像闪烁
  • 它是 "container" 而不是 "contaner"
  • 数学时间
    4 个图像 + 4 个过渡 + 4 个暂停 = 12100 / 12 = 8.3 增量计算并取整或取整您的值以用作动画关键帧步骤:

/*QuickReset*/*{margin:0;box-sizing:border-box;}

.img-container {
  position: fixed;
  width: 100%;
  height: 100%;
  background: center / cover no-repeat;
  animation: img 20s ease-in-out infinite;
}

/* Preload images to prevent flicker during animation */
.img-container:before {
  content: "";
  background-image:
    url(//placehold.it/500x300/0bf?text=1),
    url(//placehold.it/500x300/f0b?text=2),
    url(//placehold.it/500x300/bf0?text=3),
    url(//placehold.it/500x300/0fb?text=4);
}

@keyframes img {
  0%, 8% {
    background-image: url(//placehold.it/500x300/0bf?text=1);
    transform: scale(1);
  }
  
  17% {
    transform: scale(1.2);
  }
  
  25%, 33% {
    background-image: url(//placehold.it/500x300/f0b?text=2);
    transform: scale(1);
  }
  
  41% {
    transform: scale(1.2);
  }
  
  50%, 58% {
    background-image: url(//placehold.it/500x300/bf0?text=3);
    transform: scale(1);
  }
  
  66% {
    transform: scale(1.2);
  }
  
  75%, 83% {
    background-image: url(//placehold.it/500x300/0fb?text=4);
    transform: scale(1);
  }
  
  91% {
    transform: scale(1.2);
  }
}
<div class="img-container"></div>

【讨论】:

  • 不,这不是我想要的,但感谢您的帮助,i solved
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-02
  • 2016-10-11
  • 2012-10-13
  • 2011-03-24
  • 2013-05-13
  • 1970-01-01
  • 2011-03-26
相关资源
最近更新 更多