728x90
๋ฐ์ํ
Javascript Mouse Effect
Mouse ์ดํํธ ์ค ๋ง์ฐ์ค ์ปค์๋ฅผ ์์ง์ด๋ฉด ์ ์์ ์จ๊ฒจ์ง ์ฌ์ง์ด ๋ณด์ด๋ ํจ๊ณผ์ ๋๋ค.
ํต์ฌ ํฌ์ธํธ(์งํ์ค)
1. ์งํ์ค
HTML
html ์์ค์ ๋๋ค.
<main id="main">
<section id="mouseType">
<div class="mouse__cursor"></div>
<div class="mouse__cursor2"></div>
<div class="mouse__wrap">
<p>Seize the day!</p>
<p>์ค๋์ ์ฆ๊ธฐ์ธ์!</p>
</div>
</section>
</main>
CSS
css ์์ค์ ๋๋ค.
/* MouseType */
.mouse__wrap {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
color: #fff;
overflow: hidden;
/* cursor: none; */
}
.mouse__wrap p {
font-size: 2vw;
line-height: 2;
font-weight: normal;
}
.mouse__wrap p:last-child {
font-size: 3vw;
font-weight: 400;
}
.mouse__wrap p span {
border-bottom: 1px solid #ff9aa1;
color: #ff9aa1;
}
@media (max-width: 800px) {
.mouse__wrap p {
padding: 0 20px;
font-size: 20px;
line-height: 1.5;
text-align: center;
margin: 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: 200px;
height: 200px;
z-index: -1;
border-radius: 50%;
background-image: url(img/effect_bg02-min.jpg);
background-size: cover;
background-position: center center;
background-attachment: fixed;
border: 5px solid #fff;
}
Javascript
Javascript ์์ค์ ๋๋ค.
const cursor = document.querySelector(".mouse__cursor");
const circle = cursor.getBoundingClientRect();
console.log(circle);
window.addEventListener("mousemove", (e) => {
gsap.to(cursor,{duration: 0.3,
left: e.pageX - circle.width/2,
top: e.pageY- circle.height/2,
});
});
728x90
๋ฐ์ํ
'์ดํํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์์น ์ดํํธ 4 (2) | 2022.09.29 |
---|---|
๋ง์ฐ์ค ์ดํํธ 4. ์์ง์ด๋ ๊ทธ๋ฆผ (3) | 2022.09.23 |
ํจ๋ด๋์ค ์ดํํธ 5. ์ด์ง๊ฐ ํจ๊ณผ (์งํ์ค) (2) | 2022.09.20 |
์ฌ๋ผ์ด๋ ์ดํํธ 4. ๋ฒํผ ๋๋ฌ ๋๊ธฐ๊ธฐ (5) | 2022.09.19 |
๋ง์ฐ์ค ์ดํํธ 2. ๋ง์ฐ์ค ๋ฐ๋ผ๋ค๋๊ธฐ (GSAP) (3) | 2022.09.19 |
๋๊ธ