Pain is temporary Quitting lasts forever.
Pain is temporary Quitting lasts forever.
블랜딩 이펙트 - 마우스 따라 다니기
<main>
<div class="cursor"></div>
<article class="mouseCont">
<p>Pain is <em>temporary</em>Quitting lasts forever.</p>
<h2>고통은 잠깐이다. <em>포기는</em>영원히 남는다.</h2>
</article>
</main>
.mouseCont {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
color: #fff;
height: 100vh;
width: 100%;
overflow: hidden;
font-family: 'NEXONLv1Gothic';
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 orange;
color: orange;
}
.cursor {
position: absolute;
left: 0;
top: 0;
width: 20px;
height: 20px;
border-radius: 50%;
z-index: 9999;
background-color: #fff;
user-select: none;
pointer-events: none;
transition: transform 0.3s, opacity 0.2s;
mix-blend-mode: difference;
/* 디퍼런스 효과 정리하기 */
}
.cursor.active {
transform: scale(20);
}
.info.left.list li.active {
text-decoration: underline;
color: orange;
}
const w = document.querySelector('.cursor').clientWidth / 2;
const y = document.querySelector('.cursor').clientHeight / 2;
let text = 'difference';
//움직임 효과
document.addEventListener('mousemove', e => {
gsap.to('.cursor', { duration: .5, left: e.pageX - w, top: e.pageY - y });
});
//hover 효과
document.querySelectorAll('.mouseCont em').forEach(em => {
em.addEventListener('mouseenter', () => {
document.querySelector('.cursor').classList.add('active');
document.querySelector('.cursor.active').style.mixBlendMode = text;
});
em.addEventListener('mouseout', () => {
document.querySelector('.cursor').classList.remove('active');
document.querySelector('.cursor').style.mixBlendMode = 'normal';
});
});
//출력용
document.querySelectorAll('.info.left.list li').forEach(li => {
li.addEventListener('click', () => {
document.querySelectorAll('.info.left.list li').forEach(el => {
el.classList.remove('active');
});
li.classList.add('active');
text = li.innerText;
});
});