【问题标题】:CSS Slideshow is taking too long to startCSS 幻灯片启动时间过长
【发布时间】:2019-10-31 00:18:43
【问题描述】:

我正在使用一个示例来创建纯 CSS 幻灯片。一切都很好,除了当我添加一张新幻灯片时,行为发生了变化。之前,幻灯片从左到右移动,下一张慢慢进入。现在它只是幻灯片显示下面的另一张。

我知道这是一个时间问题,但我不知道如何计算它。尝试使用 5 张幻灯片的原始代码和 28 的执行时间(4 张幻灯片每张乘以 7 秒),然后查看转换。它没有显示第五张幻灯片。现在,要添加第五个,将执行时间更改为 35(5 张幻灯片每张乘以 7 秒)并查看附加的内容。第五张幻灯片,但幻灯片之间的过渡与时间为 28 的测试不同。第一面开始时间太长,并且弄乱了其余时间,我不知道为什么。

<html>
<head>
<style>
*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  display: flex;
  align-items: center;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: #3c3c3c;
}

.card {
  position: relative;  
  width: 700px;
  height: 400px;
  overflow: hidden;
  border-radius: 5px;
  box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
}

.card::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  z-index: 900;
  display: block;
  width: 100%;
  height: 100%;
  background-color: rgba(140, 22, 115, 0.2);
}

.card_part {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;  
  transform: translateX( 700px );
  background-image: url( http://www.cosat.biz/fichiers/img/Img1.png );  
  animation: opaqTransition 28s cubic-bezier(0, 0, 0, 0.97) infinite;
/* change to 35 for 5 slides*/
}

.card_part.card_part-two {
  z-index: 6;
  background-image: url( http://www.cosat.biz/fichiers/img/Img2.png );
  animation-delay: 7s;
}

.card_part.card_part-three {
  z-index: 5;
  background-image: url( http://www.cosat.biz/fichiers/img/Img3.png );
  animation-delay: 14s;
}

.card_part.card_part-four {
  z-index: 4;
  background-image: url( http://www.cosat.biz/fichiers/img/Img4.png );
  animation-delay: 21s;
}

.card_part.card_part-five {
  z-index: 3;
  background-image: url( http://www.cosat.biz/fichiers/img/Img5.png );
  animation-delay: 28s;
}

@keyframes opaqTransition {
  3% { transform: translateX( 0 ); }
  25% { transform: translateX( 0 ); }
  28% { transform: translateX( -700px ); }
  100% { transform: translateX( -700px ); }
}
</style>
</head>
<body>
<!-- Slideshow container -->
<div class="card">
  <div class="card_part card_part-one"></div> 
   <!-- Photo 2 -->
  <div class="card_part card_part-two"></div>
  <!-- Photo 3 -->
  <div class="card_part card_part-three"></div>
  <!-- Photo 4 -->
  <div class="card_part card_part-four"></div>
   <!-- Photo 5 -->
  <div class="card_part card_part-five"></div>
</div>
</body>
</html>

【问题讨论】:

  • 感谢您的帮助,英语不是我的语言...

标签: css slideshow automatic-updates


【解决方案1】:

我只是将animation 时间更改为 5 秒,一切都快了很多。您可以根据需要更改时间。

<html>
<head>
<style>
*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  display: flex;
  align-items: center;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: #3c3c3c;
}

.card {
  position: relative;  
  width: 700px;
  height: 400px;
  overflow: hidden;
  border-radius: 5px;
  box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
}

.card::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  z-index: 900;
  display: block;
  width: 100%;
  height: 100%;
  background-color: rgba(140, 22, 115, 0.2);
}

.card_part {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;  
  transform: translateX( 700px );
  background-image: url( https://github.com/Flat-Pixels/assets_hosting/blob/master/picture_slides/1.jpg?raw=true );  
  animation: opaqTransition 5s cubic-bezier(0, 0, 0, 0.97) infinite;
/* change to 35 for 5 slides*/
}

.card_part.card_part-two {
  z-index: 6;
  background-image: url( https://github.com/Flat-Pixels/assets_hosting/blob/master/picture_slides/2.jpg?raw=true );
  animation-delay: 7s;
}

.card_part.card_part-three {
  z-index: 5;
  background-image: url( https://github.com/Flat-Pixels/assets_hosting/blob/master/picture_slides/3.jpg?raw=true );
  animation-delay: 14s;
}

.card_part.card_part-four {
  z-index: 4;
  background-image: url( https://github.com/Flat-Pixels/assets_hosting/blob/master/picture_slides/4.jpg?raw=true );
  animation-delay: 21s;
}

.card_part.card_part-five {
  z-index: 4;
  background-image: url( https://github.com/Flat-Pixels/assets_hosting/blob/master/picture_slides/2.jpg?raw=true );
  animation-delay: 21s;
}

@keyframes opaqTransition {
  3% { transform: translateX( 0 ); }
  25% { transform: translateX( 0 ); }
  28% { transform: translateX( -700px ); }
  100% { transform: translateX( -700px ); }
}
</style>
</head>
<body>
<!-- Slideshow container -->
<div class="card">
  <div class="card_part card_part-one"></div> 
   <!-- Photo 2 -->
  <div class="card_part card_part-two"></div>
  <!-- Photo 3 -->
  <div class="card_part card_part-three"></div>
  <!-- Photo 4 -->
  <div class="card_part card_part-four"></div>
   <!-- Photo 5 -->
  <!-- div class="card_part card_part-five" --></div>
</div>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多