@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap");
:root {
--white: #eee;
--black: #141414;
--color: #3333ff;
scroll-behavior: smooth;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Poppins", sans-serif;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--black);
padding: 1rem;
}
.link {
font-size: 2rem;
font-weight: bold;
color: white;
text-decoration: none;
position: relative;
}
.link span,
.link i {
position: relative;
}
.link i {
margin-left: 0.5em;
}
.link .color {
width: 2em;
height: 2em;
border-radius: 2em;
background-color: var(--color);
position: absolute;
top: 50%;
transform: translatey(-50%);
left: -0.65em;
}
let link = document.querySelector(".link");
let pink = document.querySelector(".color");
let hoverTL = gsap.timeline();
hoverTL.pause();
// from, to, fromTo Tweens
hoverTL.to(pink, {
width: "calc(100% + 1.3em)",
ease: "Elastic.easeOut(0.25)",
duration: 0.4
});
hoverTL.to(pink, {
width: "2em",
left: "calc(100% - 1.45em)",
ease: "Elastic.easeOut(0.4)",
duration: 0.6
});
link.addEventListener("mouseenter", () => {
hoverTL.play();
});
link.addEventListener("mouseleave", () => {
hoverTL.reverse();
});