Hover Effects for Multiple Elements GSAP

 Hover Effects for Multiple Elements using GSAP




Snap of code are:

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


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


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

CSS
*{
    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;
    flex-direction: column;
    gap: 3rem;
}

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

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

}


Javascript

const items = document.querySelectorAll(".item");
gsap.defaults({duration:0.3})


items.forEach(element => {
    const myAnime = gsap.timeline({paused:true})
    .to(element.querySelector(".text"), {
        color:"aqua",
        scale:2,
        transformOrigin:"left center",
        x:10
    })

    .to(element.querySelector(".circle"),{
        color:"yellow",
        scale:2,
        backgroundColor:"yellow"
    },"<")


element.addEventListener("mouseenter", ()=>{
    myAnime.play();
})
element.addEventListener("mouseleave", ()=>{
    myAnime.reverse();
})
});


Video Output:




Comments

Popular posts from this blog

CSS simple grid layout

Gsap timeline position parameters

GSAP Timelines