๐ฑ ๋ง์ฐ์ค ํจ๊ณผ : ๋ง์ฐ์ค ํฌ์ธํฐ ๋ฐ๋ผ๋ค๋๊ธฐ ๐ฑ
์ด๋ฒ ์๊ฐ์๋ ๋ง์ฐ์ค ์ปค์๋ฅผ ์์ง์์ ๋ฐ๋ผ ํด๋น ์์ญ์ ์ปค์๊ฐ ๋ฟ์์ ๋ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ ํจ๊ณผ๋ฅผ ์ค์ตํด๋ณด๊ฒ ์ต๋๋ค ๐
#1. HTML / CSS ์ค์ ํ๊ธฐ
! HTML TIP !
ํ์ด์ง ์น์
๊ณผ ๋ง์ฐ์ค ์ธํฌ(์ปค์ ์์น๊ฐ ๋ฐ์ค)๋ฅผ ๊ฐ๊ฐ ๋๋์ด ๊ตฌ์กฐ์ ๋ง๊ฒ ๋ ์ด์์์ ์ง ๋ค ์คํฌ๋ฆฝํธ๋ฅผ ์ํ ์ ํ์๋ฅผ ๊ฐ๊ฐ ๋ถ์ฌํฉ๋๋ค.
๋ํ ํ
์คํธ์์ ์คํ์ผ ๋ณ๊ฒฝ ๋ฐ ์ด๋ฒคํธ๋ฅผ ๋ฐ์์ํค๊ณ ์ถ์ ๊ณณ์ ๊ฐ๊ฐ ์ ํ์๋ฅผ ์ ์ธํฉ๋๋ค.
โ๏ธ HTML ์คํฌ๋ฆฝํธ ๋ณด๊ธฐ
<section id="mouseType01">
<div class="mouse__cursor"></div>
<div class="mouse__wrap">
<p>The <span class="style1">future</span> depends on <span class="style2">what we do</span> in the <span class="style3">present</span></p>
<p><span class="style4">๋ฏธ๋</span>๋ <span class="style5">ํ์ฌ</span> ์ฐ๋ฆฌ๊ฐ <span class="style6">๋ฌด์์ ํ๋๊ฐ</span>์ ๋ฌ๋ ค ์๋ค.</p>
</div>
</section>
<div class="mouse__info">
<ul>
<li>clientX : <span class="clientX">0</span>px</li>
<li>clientY : <span class="clientY">0</span>px</li>
<li>offsetX: <span class="offsetX">0</span>px</li>
<li>offsetY: <span class="offsetY">0</span>px</li>
<li>pageX: <span class="pageX">0</span>px</li>
<li>pageY: <span class="pageY">0</span>px</li>
<li>screenX: <span class="screenX">0</span>px</li>
<li>screenY: <span class="screenY">0</span>px</li>
</ul>
</div>
! CSS TIP !
1. ์ปค์ ์์ญ ์ค์ ๊ณผ ์ขํ๊ฐ ๋ฐ์ค๋ฅผ ์ค์ ํฉ๋๋ค
2. ๊ทธ ๋ค ํ
์คํธ์์ ์ปค์๊ฐ ๋ฟ์์ ๋ ์ด๋ฒคํธ๋ฅผ ๋ฐ์์ํค๊ณ ์ถ์ ๊ณณ์ ์ ๋๋ฉ์ด์
์์ฑ์ ๋ถ์ฌํฉ๋๋ค.
โ๏ธ CSS ์คํฌ๋ฆฝํธ ๋ณด๊ธฐ : ๋ง์ฐ์ค ํฌ์ธํฐ / ์์น(์ขํ)๋ฐ์ค ์์ญ
/* mouseType */
.mouse__wrap {
width: 100%;
height: 100vh; /* vw๋ฅผ ์ฌ์ฉํ๋ฉด ์คํฌ๋กค์ด ์๊ธฐ๋ฏ๋กvh๋ก ์์
*/
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: 200;
}
.mouse__wrap p:last-child {
font-size: 3vw;
font-weight: 300;
}
.mouse__wrap p span {
padding-bottom: 3px;
border-bottom: 0.1vw solid #e7ad00;
color: #e7ad00;
}
@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 */
.mouse__cursor {
position: absolute;
left: 0;
top: 0;
width: 50px;
height: 50px;
border-radius: 50%;
border: 1px solid #fff;
background-color: rgba(255,255,255,0.1);
user-select: none; /* ์ปค์ ์ด๋ฒคํธ ๋ฐ์ํ์ง ์๊ฒ ํจ. (์ ํ๋์ง ์๊ฒ ํจ.) */
pointer-events: none;
/* perspective: 400px;
transform-style: preserve-3d; */
transition: background-color 0.3s, border-color 0.3s, transform 0.6s, border-radius 0.3s;
}
.mouse__cursor.style1 {
background-color: rgba(77, 49, 18, 0.4);
border-color: #e7ad00;
border-radius: 0;
}
.mouse__cursor.style2 {
background-color: rgba(24, 58, 78, 0.4);
border-color: #008be7;
transform: scale(2) rotateY(720deg);
}
.mouse__cursor.style3 {
background-color: rgba(77, 49, 18, 0.4);
border-color: #e7ad00;
transform: scale(5) skew(10deg);
}
.mouse__cursor.style4 {
background-color: rgba(53, 23, 65, 0.4);
border-color: #ad66ba;
transform: scale(10);
}
.mouse__cursor.style5 {
background-color: rgba(24, 58, 78, 0.4);
border-color: #008be7;
transform: scale(1);
}
.mouse__cursor.style6 {
background-color: rgba(145, 46, 86, 0.4);
border-color: #f586af;
border-radius: 0;
transform: scale(3) rotateX(545deg) skew(10deg);
}
/* .mouse__info */
.mouse__info {
position: absolute;
left: 20px;
bottom: 10px;
font-size: 14px;
line-height: 1.6;
color: #fff;
}
โ๏ธ CSS ์คํฌ๋ฆฝํธ ๋ณด๊ธฐ : ํ์ด์ง ์น์
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100%; /* 100%ํ๋ฉด ์คํฌ๋กค๋ฐ๊ฐ ์๊ธฐ์ง ์๋๋ค */
height: 100vh;
font-family: "Pretendard";
overflow: hidden; /* ์์ญ์ ๋ฒ์ด๋๋ฉด ์คํฌ๋กค ์๊ธฐ์ง ์๊ฒ ์๋ณด์ด๊ฒ ํ๊ธฐ */
background: url(../img/effect_bg04-2.jpg) no-repeat center / cover;
}
/* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง */
body.img01 {
background: url(../img/effect_bg01-2.jpg) no-repeat center / cover;
}
body.img02 {
background: url(../img/effect_bg02-2.jpg) no-repeat center / cover;
}
body.img03 {
background: url(../img/effect_bg03-2.jpg) no-repeat center / cover;
}
body.img04 {
background: url(../img/effect_bg04-2.jpg) no-repeat center / cover;
}
body.img05 {
background: url(../img/effect_bg05-2.jpg) no-repeat center / cover;
}
body.img06 {
background: url(../img/effect_bg06-2.jpg) no-repeat center / cover;
}
body.img07 {
background: url(../img/effect_bg07-2.jpg) no-repeat center / cover;
}
body.img08 {
background: url(../img/effect_bg08-2.jpg) no-repeat center / cover;
}
body.img09 {
background: url(../img/effect_bg09-2.jpg) no-repeat center / cover;
}
body.img10 {
background: url(../img/effect_bg10-2.jpg) no-repeat center / cover;
}
body::after {
/* ๊ฐ์ ์์ : ๋ฐฐ๊ฒฝ ์ ์ฒด ๋ถํฌ๋ช
๋ ์์ฐ๊ธฐ */
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100vh;
background: rgba(23, 20, 88, 0.500);
z-index: -1;
}
img {
width: 100%;
vertical-align: top; /* ์ด๋ฏธ์ง ์ ๋ ฌ */
}
a {
color: #fff;
text-decoration: none;
}
li {
list-style: none;
}
/* scroll */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: #28293600;
}
::-webkit-scrollbar-thumb {
background: rgba(136, 136, 136, 0.500);
border-radius: 20px;
}
/* layout */
#header {
z-index: 2000; /* ์ ํธ ์ธ๋ฑ์ค๋ ์๋ก ํ์ ์ฌ์ผ ํ๋ฉฐ ๊ผญ ํฌ์ง์
์ ํจ๊ป ์ฌ์ฉํด์ฃผ์ด์ผ ํ๋. */
}
#main {
width: 100%;
height: 100vh;
position: relative;
z-index: 1000;
}
#footer {
position: relative;
z-index: 3000;
}
/* header */
#header {
position: absolute;
left: 0;
top: 0;
color: #fff;
padding: 20px;
}
#header h1 {
display: inline-block;
font-weight: 200;
margin-bottom: 10px;
border-bottom: 0.5px solid #fff;
}
#header p {
font-weight: 200;
font-size: 18px;
margin-bottom: 10px;
}
#header li {
display: inline-block;
}
#header li a {
border: 1px solid #fff;
border-radius: 50%;
display: inline-block;
width: 30px;
height: 30px;
text-align: center;
line-height: 30px;
font-size: 14px;
}
#header li.active a {
background-color: #fff;
color: #282936;
}
#2. JAVASCRIPT : ์คํฌ๋ฆฝํธ ์ง๊ธฐ
์ด๋ฒคํธ ๋ฉ์๋์ธ mouseover()๊ณผ mouseout() ๊ทธ๋ฆฌ๊ณ ์์น ์์ฑ๋ค์ ํตํด ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํด๋ณด์!
๐ก ์ ์ฒด ์คํฌ๋ฆฝํธ ๋ณด๊ธฐ
//์ปค์ ์์น ์ขํ ๊ฐ
window.addEventListener("mousemove", (event) => {
document.querySelector(".clientX").innerText = event.clientX; //๋ธ๋ผ์ฐ์ ๊ธฐ์ค
document.querySelector(".clientY").innerText = event.clientY;
document.querySelector(".offsetX").innerText = event.offsetX; //์์ ๊ธฐ์ค
document.querySelector(".offsetY").innerText = event.offsetY;
document.querySelector(".pageX").innerText = event.pageX; //๋ฌธ์ ๊ธฐ์ค
document.querySelector(".pageY").innerText = event.pageY;
document.querySelector(".screenX").innerText = event.screenX; //๋๋ฐ์ด์ค ๊ธฐ์ค
document.querySelector(".screenY").innerText = event.screenY;
});
const cursor = document.querySelector(".mouse__cursor"); //์ง์ญ ๋ณ์(ํจ์์)๋ ์ด๋ฒคํธ๊ฐ ์๋ X ์ ์ญ๋ณ์๋ก ํด์ผ ์ด๋ฒคํธ๊ฐ ์๋๋๊ธฐ ๋๋ฌธ์ ์ ์ญ ๋ณ์๋ก ์์
.
//์ปค์ ์์ญ ์ ํ๊ธฐ
window.addEventListener("mousemove", (e) => {
cursor.style.left = e.clientX -25 + "px";
cursor.style.top = e.clientY -25 + "px";
});
//์ปค์ ์ด๋ฒคํธ ์๋์ํค๊ธฐ - ๊ฐ๊ฐ ์ถ๋ ฅ๋ฌธ์ผ๋ก ์คํ์ผ ์ ์ฉ - ๋นํจ์จ์
// document.querySelector(".style1").addEventListener("mouseover", () => {
// cursor.classList.add("style1");
// });
// document.querySelector(".style1").addEventListener("mouseout", () => {
// cursor.classList.remove("style1");
// });
// document.querySelector(".style2").addEventListener("mouseover", () => {
// cursor.classList.add("style2");
// });
// document.querySelector(".style2").addEventListener("mouseout", () => {
// cursor.classList.remove("style2");
// });
// document.querySelector(".style3").addEventListener("mouseover", () => {
// cursor.classList.add("style3");
// });
// document.querySelector(".style3").addEventListener("mouseout", () => {
// cursor.classList.remove("style3");
// });
// document.querySelector(".style4").addEventListener("mouseover", () => {
// cursor.classList.add("style4");
// });
// document.querySelector(".style4").addEventListener("mouseout", () => {
// cursor.classList.remove("style4");
// });
// document.querySelector(".style5").addEventListener("mouseover", () => {
// cursor.classList.add("style5");
// });
// document.querySelector(".style5").addEventListener("mouseout", () => {
// cursor.classList.remove("style5");
// });
// document.querySelector(".style6").addEventListener("mouseover", () => {
// cursor.classList.add("style6");
// });
// document.querySelector(".style6").addEventListener("mouseout", () => {
// cursor.classList.remove("style6");
// });
// for๋ฌธ : ๋ง์ฐ์ค ์ปค์ ์ด๋ฒคํธ ์๋์ํค๊ธฐ
//for๋ฌธ ์ ์ฐ๊ณ ๋ฐ๋ณต๋๋ ์คํ๋ฌธ ์ฐ๊ธฐ - ๊ทธ ๋ค ์ซ์ ์ง์ฐ๊ณ i๋ก ๋ณ๊ฒฝํ๊ธฐ
for(let i=1; i<=6; i++){
document.querySelector(".style"+ i).addEventListener("mouseover", () => {
cursor.classList.add("style" + i);
});
document.querySelector(".style"+ i).addEventListener("mouseout", () => {
cursor.classList.remove("style"+ i);
});
}
// forEach() : ๋ง์ฐ์ค ์ปค์ ์ด๋ฒคํธ ์๋์ํค๊ธฐ
num = [1,2,3,4,5,6];
num.forEach(el => {
document.querySelector(".style"+ el).addEventListener("mouseover", () => {
cursor.classList.add("style" + el);
});
document.querySelector(".style"+ el).addEventListener("mouseout", () => {
cursor.classList.remove("style"+ el);
});
});
// forEach() : ๋ง์ฐ์ค ์ปค์ ์ด๋ฒคํธ ์๋์ํค๊ธฐ
document.querySelectorAll(".mouse__wrap span").forEach((span, num) => {
span.addEventListener("mouseover", () => {
cursor.classList.add("style" + (num+1));
});
span.addEventListener("mouseout", () => {
cursor.classList.remove("style" + (num+1));
});
});
// getAttribute : ๋ง์ฐ์ค ์ปค์ ์ด๋ฒคํธ ์๋์ํค๊ธฐ
document.querySelectorAll('.mouse__wrap span').forEach((span) => {
const attr = span.getAttribute('class');
span.addEventListener("mouseover", () => {
const cursor = document.querySelector('.mouse__cursor');
cursor.classList.add(attr);
});
span.addEventListener("mouseout", () => {
const cursor = document.querySelector('.mouse__cursor');
cursor.classList.remove(attr);
});
});
โ๏ธ ์คํฌ๋ฆฝํธ ๋ณด๊ธฐ : ์๋ฐ์คํฌ๋ฆฝํธ
! JAVASCRIPT TIP !
1. ์์น(์ขํ)๊ฐ์ ์ถ๋ ฅํ๊ธฐ ์ํด innerText๋ฅผ ํตํด ์ด๋ฒคํธ ์์น ์์ฑ์ ๋ถ์ฌํฉ๋๋ค.
2. ์ปค์๋ฅผ ์ปค์ ์์ญ์ ์ค์ฌ์ ๋ง์ถ๊ธฐ ์ํด ๋ธ๋ผ์ฐ์ ๊ธฐ์ค์ ์์น ์์ฑ์ธ clientX/Y๋ฅผ ์ฌ์ฉํฉ๋๋ค.
3. ์ด ๋ ๋ฐ๋์ ๋ฌธ์์ด์ ์ถ๊ฐํ์ฌ ๊ทธ ๊ฐ์ ๋จ์๋ฅผ ์ค์ ํด์ฃผ์ด์ผ ํฉ๋๋ค!(+ "px")
4. getAttribute ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ง์ฐ์ค ์ด๋ฒคํธ ๋ฉ์๋๋ฅผ ํจ์จ์ ์ผ๋ก ์คํ์ํต๋๋ค.
5. ๊ทธ ์ธ์๋ ์๋์ ์ฃผ์์ ์ฐธ๊ณ ํ์ฌ ๋ ์์ธํ๊ฒ ์์๋ด
์๋ค!
//์ปค์ ์์น ์ขํ ๊ฐ
window.addEventListener("mousemove", (event) => {
document.querySelector(".clientX").innerText = event.clientX; //๋ธ๋ผ์ฐ์ ๊ธฐ์ค
document.querySelector(".clientY").innerText = event.clientY;
document.querySelector(".offsetX").innerText = event.offsetX; //์์ ๊ธฐ์ค
document.querySelector(".offsetY").innerText = event.offsetY;
document.querySelector(".pageX").innerText = event.pageX; //๋ฌธ์ ๊ธฐ์ค
document.querySelector(".pageY").innerText = event.pageY;
document.querySelector(".screenX").innerText = event.screenX; //๋๋ฐ์ด์ค ๊ธฐ์ค
document.querySelector(".screenY").innerText = event.screenY;
});
const cursor = document.querySelector(".mouse__cursor"); //์ง์ญ ๋ณ์(ํจ์์)๋ ์ด๋ฒคํธ๊ฐ ์๋ X ์ ์ญ๋ณ์๋ก ํด์ผ ์ด๋ฒคํธ๊ฐ ์๋๋๊ธฐ ๋๋ฌธ์ ์ ์ญ ๋ณ์๋ก ์์
//์ปค์ ์์ญ ์ ํ๊ธฐ
window.addEventListener("mousemove", (e) => {
cursor.style.left = e.clientX -25 + "px";
cursor.style.top = e.clientY -25 + "px";
});
// getAttribute : ๋ง์ฐ์ค ์ปค์ ์ด๋ฒคํธ ์๋์ํค๊ธฐ
document.querySelectorAll('.mouse__wrap span').forEach((span) => {
const attr = span.getAttribute('class');
span.addEventListener("mouseover", () => {
const cursor = document.querySelector('.mouse__cursor');
cursor.classList.add(attr);
});
span.addEventListener("mouseout", () => {
const cursor = document.querySelector('.mouse__cursor');
cursor.classList.remove(attr);
});
});
#3. ๊ฒฐ๊ณผ ๋ณด๊ธฐ ๐
'EFFECT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[EFFECT] ํ๋ด๋ ์ค ํจ๊ณผ02 : ์ค๋ฌด์ค~ํ ๋ฒํผ ์ด๋ (1) | 2022.09.14 |
---|---|
[EFFCET] ํ๋ด๋ ์ค(parallax) ํจ๊ณผ : ๋ฉ๋ด ์ด๋ (3) | 2022.09.07 |
[EFFCET] ์ด๋ฏธ์ง : ์ฌ๋ผ์ด๋ ์ ํ03 (12) | 2022.09.02 |
[EFFCET] ์ด๋ฏธ์ง : ์ฌ๋ผ์ด๋ ์ ํ02 (3) | 2022.08.30 |
[EFFECT] ์ด๋ฏธ์ง : ์ฌ๋ผ์ด๋ ์ ํ01 (2) | 2022.08.30 |
๋๊ธ