728x90
반응형
마우스 이펙트02
마우스의 위치값 표시 , 특정 글자에 갖대 대면 애니메이션 이 나온다.
HTML
<section id="mouseType">
<div class="mouse__cursor"></div>
<div class="mouse__wrap">
<p>The <span class="style1">future</span> <span class="style2">depends</span> on What we
do in the<span class="style3"> present.</span>
</p>
<p><span class="style4">미래</span>는 현재 <span class="style5">우리가</span> 무엇을 <span
class="style6">하는가에</span> 달려있다.</p>
</div>
</section>
CSS
/* mouseType */
.mouse__wrap {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
overflow: hidden;
flex-direction: column;
cursor: none;
}
.mouse__wrap p {
font-size: 2vw;
line-height: 2;
font-weight: 300;
}
.mouse__wrap p:last-child {
font-size: 3vw;
font-weight: 300;
}
.mouse__wrap p span {
border-bottom: 0.15vw dashed orange;
color: orange;
}
@media (max-width: 800px) {
.mouse__wrap p {
padding: 0 20px;
font-size: 24px;
line-height: 1.5;
text-align: center;
margin-bottom: 10px;
}
.mouse__wrap p:last-child {
font-size: 40px;
line-height: 1.5;
text-align: center;
word-break: keep-all;
}
}
.mouse__cursor {
position: absolute;
left: 0;
top: 0;
width: 10px;
height: 10px;
z-index: 9999;
border-radius: 50%;
background: rgba(255, 255, 255, 0.3);
user-select: none;
pointer-events: none;
transition: transform 0.3s, opactiy 0.2s;
}
.mouse__cursor2 {
position: absolute;
left: 0;
top: 0;
width: 30px;
height: 30px;
z-index: 9998;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
user-select: none;
pointer-events: none;
transition: transform 0.3s, opactiy 0.2s;
}
.mouse__cursor.active {
transform: scale(0);
}
.mouse__cursor2.active {
transform: scale(5);
background: rgba(255, 166, 0, 0.6);
}
.mouse__cursor.active2 {
transform: scale(0);
}
.mouse__cursor2.active2 {
transform: scale(3);
background: rgba(255, 166, 0, 0.6);
}
.mouse__cursor.active3 {
transform: scale(0);
}
.mouse__cursor2.active3 {
transform: scale(3);
background: rgba(255, 166, 0, 0.6);
}
const cursor = document.querySelector(".mouse__cursor");
const cursor2 = document.querySelector(".mouse__cursor2");
const span = document.querySelectorAll(".mouse__wrap span");
const menu = document.querySelectorAll("#header")
const modal = document.querySelectorAll(".modal__btn")
window.addEventListener("mousemove", e => {
// 커서 좌표값 할당
// cursor.style.left = e.pageX - 5 + "px";
// cursor.style.top = e.pageY - 5 + "px";
// cursor2.style.left = e.pageX - 15 + "px";
// cursor2.style.top = e.pageY - 15 + "px";
// GSAP
gsap.to(cursor, { duration: 0.3, left: e.pageX - 5, top: e.pageY - 5 });
gsap.to(cursor2, { duration: 0.8, left: e.pageX - 15, top: e.pageY - 15 });
// 오버 효과 (화살표함수에는 this가 안먹힌다.)
// mouseenter / mouseover / 이벤트 버블링
span.forEach(span => {
span.addEventListener("mouseenter", () => {
cursor.classList.add("active");
cursor2.classList.add("active");
});
span.addEventListener("mouseleave", () => {
cursor.classList.remove("active");
cursor2.classList.remove("active");
});
});
//header 오버
menu.forEach(menu => {
menu.addEventListener("mouseenter", () => {
cursor.classList.add("active2");
cursor2.classList.add("active2");
});
menu.addEventListener("mouseleave", () => {
cursor.classList.remove("active2");
cursor2.classList.remove("active2");
});
});
//소스보기 오버
modal.forEach(modal => {
modal.addEventListener("mouseenter", () => {
cursor.classList.add("active3");
cursor2.classList.add("active3");
});
modal.addEventListener("mouseleave", () => {
cursor.classList.remove("active3");
cursor2.classList.remove("active3");
});
});
});
728x90
'Effect > mouse' 카테고리의 다른 글
마우스 이펙트 05 (1) | 2022.09.28 |
---|---|
마우스 이펙트 04 (4) | 2022.09.22 |
마우스 이펙트 03 (2) | 2022.09.22 |
마우스 이펙트 01 (2) | 2022.09.05 |
댓글