<div class="container">
<div class="square"></div>
<div class="square red"></div>
<div class="square yellow"></div>
<div class="square purple"></div>
<div class="square black"></div>
<button class="animButton">Click to animate</button>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
width: 100%;
height: 100vh;
}
.square {
width: 50px;
height: 50px;
background-color: blue;
}
.red {
background-color: red;
}
.yellow {
background-color: yellow;
}
.purple {
background-color: purple;
}
.black {
background-color: black;
}
const animButton = document.querySelector(".animButton")
animButton.addEventListener("click", animateOnClick)
function animateOnClick(){
gsap.to(".square", { duration: 1, x: 200, stagger: 0.15})
}
This Pen doesn't use any external CSS resources.