<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <title>Project #5 - Cursor Effect</title>
  </head>
  <body>
    <div class="cursor"></div>

    <!-- nav -->
    <nav>
      <ul class="nav-links">
        <li>Home</li>
        <li>Services</li>
        <li>Contact</li>
      </ul>
    </nav>

    <!-- -------------------------------- -->
    <!-- JS File -->
    <script src="app.js"></script>
  </body>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(rgba(51, 51, 51, 0.5), hsla(0, 0%, 20%, 0.5)),
    url("https://cdn.pixabay.com/photo/2022/04/06/12/41/landscape-7115513_960_720.jpg");
  background-size: cover;
  background-position: center;
  height: 100vh;
  width: 100%;
  color: #fff;
  line-height: 1.8;
  cursor: none;
}

.cursor {
  width: 3rem;
  height: 3rem;
  border: solid 1px white;
  border-radius: 50%;
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition-duration: 0.3s;
  transition-timing-function: ease-in-out;
  transition-property: transform, background;
  transform-origin: 100% 100%;
  z-index: -1;
  backdrop-filter: sepia(100%);
}

nav {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 90%;
  min-height: 10vh;
  margin: auto;
}

.nav-links {
  display: flex;
  list-style-type: none;
}

.nav-links li {
  margin-left: 40px;
  font-size: 20px;
  padding: 20px;
  transition: all 0.3s ease-in-out;
}

/* Dynamic Classes */
.link-grow {
  transform: scale(2);
  background-color: rgb(50, 209, 248);
}

.hovered-link {
  color: rgb(245, 0, 0);
}

.img-focus {
  height: 5rem;
  width: 5rem;
}
const mouseCursor = document.querySelector(".cursor");
const navLinks = document.querySelectorAll(".nav-links li");

//마우스가 움직이는 순간마다 페이지에서의 위치를 받아 전달한다.
window.addEventListener("mousemove", cursor);
function cursor(e) {
  mouseCursor.style.top = e.pageY + "px";
  mouseCursor.style.left = e.pageX + "px";
}

navLinks.forEach(function (link) {
  link.addEventListener("mouseout", function () {
    mouseCursor.classList.remove("link-grow");
    link.classList.remove("hovered-link");
  });

  link.addEventListener("mouseover", function () {
    mouseCursor.classList.add("link-grow");
    link.classList.add("hovered-link");
  });
});
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.