We cannot become what we want by remaining what we are.
We cannot become what we want by remaining what we are.
마우스 이펙트 - 마우스 따라다니기
<!-- contents -->
<main>
<div class="cursor"></div>
<div class="cursor-follower"></div>
<article class="mouseCont">
<p>We cannot become what we <em>want</em> by remaining what we are.</p>
<h2>지금 상태 그대로 남아있는다면 우리는 우리가 <em>원하는</em> 모습이 될 수 없다.</h2>
</article>
</main>
<!-- //contents -->
<!-- info -->
<div class="info">
<h1><a href="index.html">Mouse Effect02 - javascript</a></h1>
<p>마우스 이펙트 - 마우스 따라다니기</p>
</div>
<div class="info right">
<ul>
<li><a href="javascriptME01.html">1</a></li>
<li class="active"><a href="javascriptME02.html">2</a></li>
<li><a href="javascriptME03.html">3</a></li>
<li><a href="javascriptME04.html">4</a></li>
<li><a href="javascriptME05.html">5</a></li>
</ul>
<ul>
<li><a href="jqueryME01.html">1</a></li>
<li><a href="jqueryME02.html">2</a></li>
<li><a href="jqueryME03.html">3</a></li>
<li><a href="jqueryME04.html">4</a></li>
<li><a href="jqueryME05.html">5</a></li>
</ul>
</div>
<div class="info left list">
<ul>
<li>pageX : <span class="pageX">0</span></li>
<li>pageY : <span class="pageY">0</span></li>
</ul>
</div>
<!-- //info left -->
.mouseCont {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
color: #fff;
width: 100%;
height: 100vh;
overflow: hidden;
font-family: 'S-CoreDream';
cursor: none;
}
.mouseCont p {
font-size: 2.5vw;
line-height: 2.3;
font-weight: 300;
}
.mouseCont h2 {
font-size: 3vw;
font-weight: normal;
font-weight: 400;
}
.mouseCont em {
font-style: normal;
border-bottom: 0.2vw dashed #F4FF52;
color: #F4FF52;
}
.cursor {
position: absolute;
left: 0; top: 0;
width: 10px;
height: 10px;
border-radius: 50%;
z-index: 9999;
background-color: rgba(255,255,255,0.1);
user-select: none;
pointer-events: none;
transition: transform 0.3s, opacity 0.2s;
}
.cursor.active {
opacity: .5;
transform: scale(0);
}
.cursor.show {
opacity: .5;
transform: scale(10);
background: rgb(0, 225, 255, 0.6);
}
.cursor-follower {
position: absolute;
width: 30px;
height: 30px;
border-radius: 50%;
background: rgba(255,255,255,0.3);
user-select: none;
pointer-events: none;
transition: transform 0.6s ease-in-out, opacity 0.2s ease-in-out;
}
.cursor-follower.active {
transform: scale(5);
background: #e71d358a;
}
.cursor-follower.show {
transform: scale(5);
background: rgb(0, 225, 255, 0.6);
}
.info,
.info a {
cursor: none;
}
const cursor = document.querySelector(".cursor");
const follower = document.querySelector(".cursor-follower");
// 움직임 효과
document.addEventListener("mousemove", (e) => {
// cursor.style.left = e.pageX -5 + "px";
// cursor.style.top = e.pageY -5 + "px";
// follower.style.left = e.pageX -15 + "px";
// follower.style.top = e.pageY -15 + "px";
// let x1 = e.pageX -5 + "px"
// let y1 = e.pageY -5 + "px"
// let x2 = e.pageX -15 + "px"
// let y2 = e.pageY -15 + "px"
// cursor.style.cssText = "left:" + x1 + "; top:" + y1 ;
// follower.style.cssText = "left:" + x2 + "; top:" + y2 ;
gsap.to(cursor, {duration: 0.3, left: e.pageX -5, top: e.pageY -5});
gsap.to(follower, {duration: 0.8, left: e.pageX -15, top: e.pageY -15});
})
// 오버 효과
document.querySelectorAll(".mouseCont em").forEach((em) => {
em.addEventListener("mouseenter", () => {
cursor.classList.add("active");
follower.classList.add("active");
});
em.addEventListener("mouseleave", () => {
cursor.classList.remove("active");
follower.classList.remove("active");
});
});
// 오버 효과2
document.querySelectorAll(".info").forEach((em) => {
em.addEventListener("mouseenter", () => {
cursor.classList.add("show");
follower.classList.add("show");
});
em.addEventListener("mouseleave", () => {
cursor.classList.remove("show");
follower.classList.remove("show");
});
});
// 출력용
window.addEventListener("mousemove", (e) => {
document.querySelector(".pageX").innerText = e.pageX + "px"; //페이지 X좌표 기준
document.querySelector(".pageY").innerText = e.pageY + "px"; //페이지 Y좌표 기준
});
// 소스보기 실행함수
modal();