<div class="container">
    <div class="square"></div>
    <button class="animButton">Click to animate</button>
  </div>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.container {
  width: 100%;
  height: 100vh;
}

.square {
  width: 100px;
  height: 100px;
  background-color: blue;
}
const animButton = document.querySelector(".animButton")
animButton.addEventListener("click", animateOnClick)
const animation = gsap.to(".square", { duration: 1, x: 200, paused: true})
function animateOnClick(){
  animation.restart()
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/gsap/3.7.1/gsap.min.js