It is better to fail in originality than to succeed in imitation.
It is better to fail in originality than to succeed in imitation.
마우스 이펙트 - 마우스 따라 다니기
<main>
<div class="cursor"></div>
<article class="mouseCont">
<p><span class="style1">It is better</span> to fail in <span class="style2">originality</span> than to <span
class="style3">succeed in</span>imitation.</p>
<h2><span class="style1">창의적으로</span> 실패하는 것이 <span class="style2">모방해서</span>성공하는 것
<span class="style3">보다 낫다.</span></h2>
</article>
</main>
.mouseCont {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
color: #fff;
height: 100vh;
width: 100%;
overflow: hidden;
font-family: 'NEXONLv1Gothic';
cursor: none;
}
.mouseCont p {
font-size: 2.5vw;
line-height: 2.3;
font-weight: 300;
}
.mouseCont h2 {
font-size: 3vw;
font-weight: normal;
}
.mouseCont span {
font-style: normal;
border-bottom: 0.2vw dashed #fff;
}
.cursor {
position: absolute;
left: 0;
top: 0;
width: 50px;
height: 50px;
border-radius: 50%;
border: 3px solid #fff;
z-index: 9999;
background-color: rgb(255, 255, 255, 0.1);
user-select: none;
pointer-events: none;
transition:
background-color 0.2s,
border-color 0.2s,
border-radius 0.2s,
transform 0.6s;
}
.cursor.style1 {
background-color: rgba(255, 165, 0, 0.4);
border-color: orange;
}
.cursor.style2 {
background-color: rgba(208, 158, 248, 0.178);
border-color: rgb(140, 0, 255);
transform: rotateY(720deg) scale(2);
}
.cursor.style3 {
border-color: #fff;
border-radius: 10px;
width: 100px;
height: 100px;
background-image: url(../assets/img/너굴.JPG);
background-size: cover;
background-position: center;
}
.cursor.style4 {
border: none;
background: none;
width: 100px;
height: 100px;
background-image: url(../assets/img/HI.png);
background-size: cover;
background-position: center;
}
.cursor.style5 {
border-radius: 50px;
background-color: rgba(255, 115, 0, 0.178);
border-color: #8B4513;
transform: scale(5);
}
.cursor.style6 {
background-color: rgba(218, 112, 214, 0.014);
border-color: rgba(250, 36, 243, 0.795);
transform: rotateX(720deg) scale(2);
}
//출력용
window.addEventListener("mousemove", function (e) {
document.querySelector(".clientX").innerText = e.clientX + "px";
document.querySelector(".clientY").innerText = e.clientY + "px";
document.querySelector(".offsetX").innerText = e.offsetX + "px";
document.querySelector(".offsetY").innerText = e.offsetY + "px";
document.querySelector(".pageX").innerText = e.pageX + "px";
document.querySelector(".pageY").innerText = e.pageY + "px";
document.querySelector(".screenX").innerText = e.screenX + "px";
document.querySelector(".screenY").innerText = e.screenY + "px";
});
//마우스 움직이기
window.addEventListener("mousemove", function (e) {
// document.querySelector(".cursor").style.left = e.clientX - 25 + "px";
// document.querySelector(".cursor").style.top = e.clientY - 25 + "px";
let x = e.clientX - 25 + "px";
let y = e.clientY - 25 + "px";
document.querySelector(".cursor").style.cssText = "left:" + x + "; top:" + y;
});
let spanBox = document.querySelectorAll(".mouseCont span");
spanBox.forEach((ele, index) => {
console.log(ele);
ele.addEventListener("mouseover", function(){
document.querySelector(".cursor").classList.add(`style${index + 1}`);
})
ele.addEventListener("mouseout", function(){
document.querySelector(".cursor").classList.remove(`style${index + 1}`);
})
});
//getAtrribute()
// document.querySelectorAll(".mouseCont span").forEach((element) => {
// let style = element.getAttribute("class");
// element.addEventListener("mouseover", () => {
// document.querySelector(".cursor").classList.add(style);
// });
// element.addEventListener("mouseout", () => {
// document.querySelector(".cursor").classList.remove(style);
// });
// })