JSFiddle - React, Tailwind, and code Playground

HTML

<div class="block"></div>

CSS

*{margin: 0; padding: 0;}

html, body {
    width: 100%;
    height: 100%;
}

.block {
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   width: 200px;
   height: 200px;
   margin: auto;
   position: absolute;
   background-color: red;
}

.offset {
  /*   margin-left: 0; */
    transition: 2s ease;
}

JavaScript

$(".block").click(function () {
    var $this = $(this);
    $this.css("margin-left", $this.offset().left);
      
    setTimeout(function (){
      $this.toggleClass('offset');
      $this.css("margin-left", 0);
    }, 0);
    
});