728x90
반응형
마우스 이펙트 05
기울기 효과 / 글씨 반전효과
script 코드
const mouseMove = (e) => {
// 마우스 좌표값
let mousePageX = e.pageX;
let mousePageY = e.pageY;
// 마우스 좌표 기준점 가운데로 변경
let centerPageX = window.innerWidth / 2 - mousePageX;
let centerPageY = window.innerHeight / 2 - mousePageY;
// 최소값은 -100 최대값은 100설정 **
let maxPageX = Math.max(-200, Math.min(200, centerPageX));
let maxPageY = Math.max(-200, Math.min(200, centerPageY));
// 각도 줄이는 설정
let anglePageX = maxPageX * 0.1;
let anglePageY = maxPageY * 0.1;
// 부드럽게 설정
let softPageX = 0, softPageY = 0;
softPageX += (anglePageX - softPageX) * 0.4;
softPageY += (anglePageY - softPageY) * 0.4;
// 이미지 움직이기
const imgMove = document.querySelector(".mouse__img");
imgMove.style.transform = "perspective(600px) rotateX(" + softPageY + "deg) rotatey(" + -softPageX + "deg)"
// 커서
gsap.to(".mouse__cursor", { duration: .3, left: mousePageX - 50, top: mousePageY - 50 })
// 출력
document.querySelector(".mousePageX").textContent = mousePageX;
document.querySelector(".mousePageY").textContent = mousePageY;
document.querySelector(".centerPageX").textContent = centerPageX;
document.querySelector(".centerPageY").textContent = centerPageY;
document.querySelector(".maxPageX").textContent = maxPageX;
document.querySelector(".maxPageY").textContent = maxPageY;
document.querySelector(".anglePageX").textContent = Math.round(anglePageX);
document.querySelector(".anglePageY").textContent = Math.round(anglePageY);
};
window.addEventListener("mousemove", mouseMove);
HTML 코드 보기
<main id="main">
<section id="mouseType">
<div class="mouse__cursor"></div>
<div class="mouse__wrap">
<div class="mouse__img">
<figure>
<img src="../assets/img3/effect_bg05-min.jpg" alt="이미지" />
</figure>
<figcaption>
<p>The future depends on What we do in the present.</p>
<p>미래 는 현재 우리가 무엇을 하는가에 달려있다.</p>
</figcaption>
</div>
</div>
</section>
<div class="mouse__info">
<ul>
<li>mousePageX : <span class="mousePageX">0</span>px</li>
<li>mousePageY : <span class="mousePageY">0</span>px</li>
<li>centerPageX : <span class="centerPageX">0</span>px</li>
<li>centerPageY : <span class="centerPageY">0</span>px</li>
<li>maxPageX : <span class="maxPageX">0</span>px</li>
<li>maxPageY : <span class="maxPageY">0</span>px</li>
<li>anglePageX : <span class="anglePageX">0</span>px</li>
<li>anglePageY : <span class="anglePageY">0</span>px</li>
</ul>
</div>
</main>
CSS 코드 보기
/* mouseType */
.mouse__wrap {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
color: #fff;
width: 100%;
height: 100vh;
overflow: hidden;
cursor: none;
}
.mouse__img {
transform: perspective(600px) rotateX(0deg) rotatey(0deg);
transform-style: preserve-3d;
will-change: transform;
transition: all 0.3s;
}
.mouse__wrap figure {
width: 50vw;
position: relative;
}
.mouse__img figure::before {
content: '';
position: absolute;
left: 5%;
bottom: -30px;
width: 90%;
height: 40px;
background: url(../assets/img3/effect_bg05-min.jpg) center no-repeat;
background-size: 100% 40px;
filter: blur(15px) grayscale(50%);
z-index: -1;
opacity: 0.7;
}
.mouse__img figcaption {
position: absolute;
left: 50%;
top: 50%;
font-size: 1vw;
line-height: 1.6;
transform: translate3d(-50%, -50%, 100px);
padding: 1vw;
word-spacing: nowrap;
text-align: center;
background: rgba(0, 0, 0, 0.4);
}
.mouse__cursor {
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 100px;
border-radius: 50%;
background: #fff;
border-radius: 50%;
z-index: 1000;
user-select: none;
pointer-events: none;
mix-blend-mode: difference;
}
.mouse__info {
position: absolute;
left: 20px;
bottom: 10px;
font-size: 14px;
line-height: 1.6;
color: #fff;
}
728x90
'Effect > mouse' 카테고리의 다른 글
마우스 이펙트 04 (4) | 2022.09.22 |
---|---|
마우스 이펙트 03 (2) | 2022.09.22 |
마우스 이펙트 02 (2) | 2022.09.19 |
마우스 이펙트 01 (2) | 2022.09.05 |
댓글