Move cursor using Javascript on a web front page

This project involves creating an interactive web page where the cursor movement is visually enhanced using JavaScript. When the user moves their mouse across the web page, a custom animation or effect follows the cursor, providing a dynamic and engaging user experience. This feature can be utilized to add creative elements to websites, making them more interactive and user-friendly.

HTML, CSS

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Move Cursor</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            height: 100vh;
            background-color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }
        .cursor {
            width: 20px;
            height: 20px;
            background-color: red;
            border-radius: 50%;
            position: absolute;
            pointer-events: none;
            transform: translate(-50%, -50%);
        }
    </style>
</head>
<body>
    <div class="cursor" id="cursor"></div>
    <script>
        const cursor = document.getElementById("cursor");

        // Move the cursor element to follow the mouse
        document.addEventListener("mousemove", (event) => {
            cursor.style.left = `${event.clientX}px`;
            cursor.style.top = `${event.clientY}px`;
        });
    </script>
</body>
</html>

JS Code

// script.js
document.getElementById("loginForm").addEventListener("submit", function (e) {
    e.preventDefault();
    const email = document.getElementById("email").value;
    const password = document.getElementById("password").value;
    alert(`Email: ${email}\nPassword: ${password}`);
});

Technologies Used

  • HTML: To structure the web page.
  • CSS: To style the web page and define the custom cursor design.
  • JavaScript: To implement the logic for tracking mouse movements and applying animations.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top