JSFiddle - React, Tailwind, and code Playground

HTML

<div class="circle">Кликни на меня</div>

CSS

@keyframes circle-animate-in {
  0% {
    margin: 0;
  }
  
  50% {
    margin-left: 200px;
    margin-top: 0;
  }
  
  to {
    margin-left: 200px;
    margin-top: 50px;
  }
}

@keyframes circle-animate-out {
  0% {
    margin-left: 200px;
    margin-top: 50px;
  }
  
  50% {
    margin-left: 200px;
    margin-top: 0;
  }
  
  to {
    margin: 0;
  }
}

.circle {
  width: 90px;
  height: 90px;
  background-color: #fff;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 0 25px 3px #000;
  transition: .3s ease;
}

.circle-animate-in {
  transition: .3s ease;
  animation-name: circle-animate-in;
  animation-duration: 2s;
  animation-timing-function: ease;
  animation-fill-mode: forwards;
}

.circle-animate-out {
  transition: .3s ease;
  animation-name: circle-animate-out;
  animation-duration: 2s;
  animation-timing-function: ease;
  animation-fill-mode: forwards;
}

body {
  background-color: gray;
}

JavaScript

const circle = document.querySelector('.circle');
let i = 1;
circle.addEventListener('click', function() {
	if(i) {
  	this.classList.remove('circle-animate-out');
  	this.classList.add('circle-animate-in');
    i = 0;
  } else {
  	this.classList.remove('circle-animate-in');
  	this.classList.add('circle-animate-out');
    i = 1;
  }
})