Gsap effect on click

 Gsap effect on click

 
<div class="item">
    <div class="circle"></div>
    <h1 class="head">Angela</h1>
  </div>


Here is the same code, small gsap effect on click;


*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: rgb(10, 8, 19);
    color: white;
    font-family: sans-serif;
}

.item{
    display: flex;
    gap: 1rem;
    align-items: center;
    cursor: pointer;
}

.circle{
    height: 20px;
    width: 20px;
    background-color: white;
    border-radius: 50%;

}


Javascript;


gsap.defaults({duration:0.2})
const myAnime = gsap.timeline({paused:"true"})
    .to(".head", {
        fontSize: "3rem",
        color: "greenyellow",
        x:30
    })
    .to(".circle", {
        backgroundColor : "yellow",
        scale:4
    }, "<")

   
document.querySelector(".item").addEventListener("mouseenter", ()=>{
    myAnime.play();

})
document.querySelector(".item").addEventListener("mouseleave", ()=>{
    myAnime.reverse();

})


You can use gsap.timeline({paused:"true"}) initially to make animation paused, instead of window.onload = ()=>{myAnime.pause()}

also that default value affect to overall animation timings

Comments

Popular posts from this blog

CSS simple grid layout

Gsap timeline position parameters

GSAP Timelines