HTML
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="cursorItem">
<span class="circle"></span>
</div>
<div class="container">
<div class="neumorphism">
<h1 class="question">뉴모피즘을 아십니까?</h1>
<div class="buttons">
<button class="button yes">네</button>
<button class="button no">아니오</button>
</div>
</div>
</div>
<script src="./mouse.js"></script>
</body>
</html>
CSS
@font-face {
font-family: "KBIZHanmaumMyungjo";
src: url("https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_one@1.0/KBIZHanmaumMyungjo.woff")
format("woff");
font-weight: normal;
font-style: normal;
}
body {
font-family: "KBIZHanmaumMyungjo";
overflow: hidden;
}
* {
margin: 0;
padding: 0;
}
.cursorItem {
position: absolute;
top: 0;
left: 0;
z-index: 1000;
pointer-events: none;
mix-blend-mode: multiply;
opacity: 1;
}
.cursorItem .circle {
position: fixed;
display: block;
width: 120px;
height: 120px;
margin: -60px 0 0 -60px;
background: #493dde;
border-radius: 50%;
transition: all 0.2s ease-in-out;
}
.container {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #dde1e7;
}
.neumorphism {
height: 250px;
width: 500px;
background-color: #dde1e7;
border-radius: 5px;
box-shadow: inset -3px -3px 7px #ffffff73,
inset 3px 3px 5px rgba(94, 104, 121, 0.288);
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.question {
height: 55%;
width: 100%;
text-align: center;
line-height: 150px;
color: #767676;
}
.buttons {
display: flex;
width: 100%;
height: 45%;
justify-content: center;
align-items: center;
}
.button {
flex-grow: 1;
height: 100%;
border: none;
background-color: transparent;
box-shadow: inset -2px -2px #ffffff73,
inset -3px 0px 5px rgb(94 104 121 / 29%);
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
color: #767676;
transition: all 1s;
}
.button:hover {
font-color: #000000;
font-weight: 800;
background-color: #ffffff73;
}
JavaScript
let cursorItem = document.querySelector(".cursorItem");
let circle = document.querySelector(".circle");
let yes = document.querySelector(".yes");
let no = document.querySelector(".no");
let x = 0,
y = 0;
let mx = 0,
my = 0;
window.onload = function () {
// 네 부분 마우스
yes.addEventListener("mouseover", function (e) {
circle.style.transform = "scale(0.3)";
});
yes.addEventListener("mouseout", function (e) {
circle.style.transform = "scale(1)";
});
// 아니오 부분 마우스
no.addEventListener("mouseover", function (e) {
circle.style.transform = "scale(0.3)";
});
no.addEventListener("mouseout", function (e) {
circle.style.transform = "scale(1)";
});
window.addEventListener("mousemove", function (e) {
x = e.clientX;
y = e.clientY;
// cursorItem.style.transform = "translate(" + x + "px, " + y + "px )";
});
loop();
};
function loop() {
mx += (x - mx) * 0.09;
my += (y - my) * 0.09;
cursorItem.style.transform = `translate(${mx}px, ${my}px)`;
requestAnimationFrame(loop);
}