1

I tested with the following answers:

but the animation duration and timeline (for example, from step by step, from start to end) did not work. The three images need to be in the same place at once.

I wanted to use https://codepen.io/jay-bee-why/pen/Htejl, but unfortunately I do not want to use jQuery. I am CSS and JavaScript purist.

An image is worth a thousand words. You will understand easily the image. I also provide very small snippet code box.

example

  .flipping-images
  {
    align-items: center;
    display: flex;
    flex-flow: row nowrap;
    height: 80%;
    justify-content: center;
    /* opacity: 0; */
    position: relative;
    transform: translateX(100%);
    width: 22%;
  }
.show-l
{
  animation: show-image 5s ease-in-out 300ms infinite;
  left: 0;
  position: absolute;
  transform-origin: left;
}

.hide-l
{
  animation: hide-image 5s ease-in-out 800ms infinite;
  position: absolute;
  transform-origin: left;
}

.hide-l2
{
  animation: hide-image 5s ease-in-out 600ms infinite;
  position: absolute;
  transform-origin: right;
}
@keyframes hide-image
{
  0%
  {
    left: 0;
    transform: rotateY(0deg);
  }

  30%
  {
    left: 10%;
    transform: rotateY(0deg);
  }

  50%
  {
    opacity: 1;
  }

  100%
  {
    left: -100%;
    opacity: 0;
    transform: rotateY(90deg);
  }
}

@keyframes show-image
{
  0%
  {
    left: 100%;
    transform: rotateY(90deg);
  }

  30%
  {
    left: 110%;
    transform: rotateY(90deg);
  }

  100%
  {
    left: 0%;
    transform: rotateY(0deg);
  }
}
  <div class="flipping-images">
    <img class="show-l"   src="https://via.placeholder.com/432x864/fdc34f/FEFEFE?text=1">
    <img class="hide-l2"   src="https://via.placeholder.com/432x864/3e72ff/FEFEFE?text=2">
    <img class="hide-l"   src="https://via.placeholder.com/432x864/222222/FEFEFE?text=3">
  </div>
Oo'-
  • 203
  • 6
  • 22

1 Answers1

1

I'm not sure I understand your image since it says the second image should disappear but it also says the animation is infinite. I hope it's working as you intended, if not just leave a comment on what needs to be fixed.

I'm using the animationend event to control the animations.

var counter = 1;
var div = document.querySelector('.flipping-images');
var images = document.querySelectorAll('.flipping-images img');

var showNext = function () {
  counter++;
  if (counter > 3) counter = 1;
  div.classList.remove('image1', 'image2', 'image3')
  div.classList.add('image'+counter);
};

for (var img of images) {
  img.addEventListener('animationend', showNext);
  img.addEventListener('click', showNext);
}

document.querySelector('#next').addEventListener('click', showNext);
.flipping-images {
  perspective: 300px;
}
.flipping-images img {
  display: none;
  animation: rotate 5s linear 1;
}
.flipping-images.image1 img:nth-child(1),
.flipping-images.image2 img:nth-child(2),
.flipping-images.image3 img:nth-child(3) {
  display: block;
}
.flipping-images.image2 img:nth-child(2) {
  animation: rotate 5s linear infinite;
}
@keyframes rotate {
  0% { transform: rotateY(-45deg); }
  100% { transform: rotateY(45deg); }
}
button {
  margin: 1em;
}
<div class="flipping-images image1">
  <img src="https://via.placeholder.com/100x100/fdc34f/FEFEFE?text=1">
  <img src="https://via.placeholder.com/100x100/3e72ff/FEFEFE?text=2">
  <img src="https://via.placeholder.com/100x100/222222/FEFEFE?text=3">
</div>

<button id="next">Next</button>
rafaelcastrocouto
  • 11,781
  • 3
  • 38
  • 63
  • It is exactly what I wanted, but the image 2 need to rotate from right to left, then to 3. Actually I want this animation to be automatic without clicking or hovering. – Oo'- Dec 30 '19 at 00:34
  • Observe that I wanted 360deg (360 / 3 elements = 120deg). – Oo'- Dec 30 '19 at 00:42
  • 1
    It seems I solved, @rafaelcastrocouto. I changed -45deg for 0, and 45deg for 360deg, and I created a reverse-rotate keyframe for nth-child(2), and applied from -360deg to 0deg. – Oo'- Dec 30 '19 at 01:07
  • in spite of this, the animation was totally wrong in both 45 and 360 deg, and it was my fault for not explaining well. For example, I am trying to set: https://i.imgur.com/8BvEZO4.png. – Oo'- Dec 30 '19 at 13:57
  • It seems that I solved. Here is the small snippet: https://codepen.io/gusbemacbe/pen/vYEeErr – Oo'- Dec 30 '19 at 14:18