Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

html - Continues slider using css3 animation keyframes

I am building a slider using css3. Now slider is running continuously but the flow is not right. After slide 4 the slider is going back from left to right all the way down to the first slide.

What I want after the last slide the first slide should come from right to left as it is coming in manner for other slide.

Will it be possible by css only?

@keyframes slide{
  0%{ transform:translateX(0px) }
  25%{ transform:translateX(-200px) }
  50%{ transform:translateX(-400px) }
  75%{ transform:translateX(-600px) }
  100%{ transform:translateX(0px) }
}

fiddle

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have set a different solution to avoid duplicating the first image

The animation is more complex, but you can reuse it setting delays

#slideshow {
  position: relative;
  width: 200px;
  height: 400px;
  border: 5px solid #fff;
  overflow: hidden;
}
#slideshow img {
  position: absolute;
  left: 0px;
  top: 0;
  animation: slide 5s infinite;
}
#slideshow img:nth-child(2) {
  animation-delay: -1.25s;
}
#slideshow img:nth-child(3) {
  animation-delay: -2.5s;
}
#slideshow img:nth-child(4) {
  animation-delay: -3.75s;
}
@keyframes slide {
  0% {
    transform: translateX(0px);
  }
  20% {
    transform: translateX(0px);
  }
  25% {
    transform: translateX(-200px);
    opacity: 1;
  }
  30% {
    transform: translateX(-200px);
    opacity: 0;
  }
  90% {
    transform: translateX(200px);
    opacity: 0;
  }
  95% {
    transform: translateX(200px);
    opacity: 1;
  }
  100% {
    transform: translateX(0px);
    opacity: 1;
  }
  }
<div id="slideshow">
  <img src="http://placehold.it/200x400/4F77AA/FFFFFF">
  <img src="http://placehold.it/200x400/72A94C/FFFFFF">
  <img src="http://placehold.it/200x400/A94F83/FFFFFF">
  <img src="http://placehold.it/200x400/F9E934/FFFFFF">
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...