Animated Cursor Using HTML, CSS & JavaScript


Hello wizards, I hope you are doing great. Today in this blog you’ll learn how to create the "Animated Cursor" project using HTML, CSS & JavaScript. 

Preview 


In the above video, you’ve seen the preview of the "Animated Cursor" project and I hope now you are able to create this type of project. If not, I have provided all the HTML CSS and JavaScript code below. 

Animated Cursor [Source Code] 

To get the following HTML, CSS & JS code for the Animated Cursor project. You need to create three files one is a HTML file, second one is a CSS file and the another one is JS file. After creating these three files then you can copy-paste the given codes on your document. 

Remember, you’ve to create a file with .html extension for HTML code, .css extension for CSS code and .js for JavaScript code.

You can also download all source code files from the given download button.

HTML
<!DOCTYPE html>
<html lang="en">

<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>Animated Cursor</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>

    <div class="cursor">

    </div>

    <div class="context">
        <h1>Developer Pani</h1>
    </div>

    <script src="index.js"></script>
</body>

</html>
CSS
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: "Poppins", sans-serif;
  cursor: none;
  background-color: black;
}

h1 {
  color: white;
  font-size: 100px;
}

.cursor {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: skyblue;
  pointer-events: none;
  box-shadow: 0 0 20px skyblue, 0 0 60px skyblue, 0 0 100px skyblue;
  z-index: 999;
  display: none;
  position: fixed;
  transform: translate(-50%, 50%);
  animation: colors 3s infinite;
  -webkit-animation: colors 3s infinite;
}

@keyframes colors {
  0% {
    filter: hue-rotate(0deg);
    -webkit-filter: hue-rotate(0deg);
  }
  100% {
    filter: hue-rotate(360deg);
    -webkit-filter: hue-rotate(360deg);
  }
}

.cursor::before {
  content: "";
  position: absolute;
  transform: translate(-30%, -30%);
  width: 50px;
  height: 50px;
  background: skyblue;
  border-radius: 50%;
  opacity: 0.2;
}
JavaScript
const curserEl = document.querySelector(".cursor");
var timeout;

document.addEventListener("mousemove",movement);

function movement(e){
   console.log("moving")
        let x = e.pageX;
        let y = e.pageY;
        curserEl.style.left = x + "px";
        curserEl.style.top = y + "px";
        curserEl.style.display = "block"

        clearTimeout(timeout)
        timeout = setTimeout(() => {
        curserEl.style.display = "none"
        }, 2000);
}

document.addEventListener("mouseout",()=>{
    curserEl.style.display = "none"
})
You have to wait 15 seconds.

Generating Download Link...

Post a Comment

Previous Post Next Post