Cause:
The behavior that will be visible is expected to depend on the @keyframes and animation-direction settings. When the animation direction is specified as an alternative, UA performs animation from 0 to 100 for iterations with an odd number, from 100 to 0 for even iterations.
According to your keyframes, transform goes from rotateY(180deg) to rotateY(0deg) by 1% of the duration of the animation itself, so during odd iterations you don't see visible rotation (since the duration is quite rotateY(180deg) ), and it comes from rotateY(180deg) (from 100%) to rotateY(0deg) (99%), because of which you also do not see visible rotation during even numbered iterations.
The problem with writing keyframes for the forward direction and reusing for the reverse (using animation-direction ) is that this can only be done when the states are the same for both. In this case, this does not happen because the element must be in a non-rotating state while moving forward and must have rotateY(180deg) during the reverse movement.
Decision:
In order for an element to be seen in its rotated state, transform must be preserved for some time. So, for your case, it is better to end the animation-direction: alternate setting and write both forward and reverse movements in the key frames themselves, as in the fragment below.
( Note: Since we record both reverse and reverse movements in key frames, you may need to double the animation-duration value.)
@keyframes fish01 { 0% { left: 0%; transform: rotateY(0deg); } 49.5% { left: 90%; transform: rotateY(0deg); } 50.5% { left: 90%; transform: rotateY(180deg); } 100% { left: 0%; transform: rotateY(180deg); } } body { background-color: black; } div { position: absolute; margin-left: 18%; margin-top: 3%; width: 800px; height: 500px; border: 5px double #DDDDDD; border-radius: 1em 1em; background-image: url("https://i.onthe.io/vllkyt28101smv87bg.349283fe.jpg"); } div img:nth-child(1) { float: left; position: absolute; margin: 0px; top: 20%; width: 100px; height: 50px; transform: scale(1.5, 1.5); animation-name: fish01; animation-duration: 10s; animation-fill-mode: forwards; animation-iteration-count: infinite; animation-timing-function: ease-in; } div img:nth-child(2) { float: left; position: absolute; top: 20%; left: 60%; }
<section> <div> <img src="https://www.hyperone.com.eg/media/catalog/product/cache/4/thumbnail/9df78eab33525d08d6e5fb8d27136e95/f/i/fish_1.png" /> <img src="http://www.pets4homes.co.uk/images/fish_hero.png" /> </div> </section>
source share