Hello! I need the help of knowledgeable people, my knowledge of JS is nearing zero, I already just broke my whole head)
The problem is as follows:
There are two blocks (div), one of them is initially hidden outside the screen.
When you press a button, the visible block flies to the right side of the screen, and the hidden flies to the left in its place.
There are no problems with the animation itself, and it is even possible to launch it by clicking on the button, but only once, pressing it again does not work (that is, you need to restart the animation each time).
But the main problem is how, when you click on another button, launch the same animation in the opposite direction? Those. so that the blocks rose to their original position.
For clarity, here you can see the result I achieved. Block "Fill out an application", just below the middle of the page, the button on the right in this block. Here is the code I used:
HTML:
<div class="zakaz-form switch-form">Π‘ΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ 1-Π³ΠΎ Π±Π»ΠΎΠΊΠ° + 1-Ρ ΠΊΠ½ΠΎΠΏΠΊΠ°</div> <div class="cons-form switch-form">Π‘ΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ 2-Π³ΠΎ Π±Π»ΠΎΠΊΠ° + 2-Ρ ΠΊΠ½ΠΎΠΏΠΊΠ°</div> CSS animation:
.zakaz-form{ animation: switch-zakaz forwards 3s; -webkit-animation-play-state:paused; animation-play-state:paused; } @keyframes switch-zakaz { 0% { opacity: 1; left: 0; } 20% { opacity: 1; left: 0; } 100% { opacity: 0; left: 95%; } } .cons-form{ animation: switch-cons forwards 3s; -webkit-animation-play-state:paused; animation-play-state:paused; } @keyframes switch-cons { 0% { opacity: 0; left: -1000px; } 80% { opacity: 1; left: calc(50% - 275px); } 100% { opacity: 1; left: calc(50% - 275px); } } .start-anim { -webkit-animation-play-state:running; animation-play-state:running; } JS - start the animation by clicking on the button:
jQuery(document).ready(function($){ $(function(){ $('.cons-button').click(function(){ $('.switch-form').toggleClass('start-anim'); }); }); }); Thank you in advance for any help!
UPD: [An example of an incomplete solution] - when you click on the "Show the first block" button, you need the animation to run in the opposite direction.