본문 바로가기
JavaScript

[JavaScript] 마우스 위치대로 따라다니는 효과 주기

by dev또리 2023. 4. 30.
728x90

 

HTML

 

<div class="cursor">
  <div class="text">또리</div>
  <div class="text">또리</div>
  <div class="text">또리</div>
  <div class="text">또리</div>
  <div class="text"><span>또리</span></div>
</div>

 

 

 

 

CSS

 

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  background: #161616;
  overflow: hidden;
}

.text {
  position: absolute;
  pointer-events: none;
  font-family: venn-extended, sans-serif;
  font-weight: 700;
  font-style: normal;
  font-size: 6em;
  -webkit-text-stroke: 1px #fff;
  /*font-weight: 500;
  text-transform: uppercase;*/
  color: #161616;
}

.text span {
  color: #fff;
}

 

 

 

 

JS

 

document.addEventListener("mousemove", e => {
  gsap.to(".text", {
    x: e.clientX,
    y: e.clientY,
    stagger: { // wrap advanced options in an object
      each: -0.02,
      ease: "power2.inOut",
    }
  })
})

 

 

 

728x90

댓글