Custom Cursor Animation - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Cursor Animation</title> <style> body { margin: 0; padding: 0; overflow: hidden; font-family: 'Arial', sans-serif; background-color: #282c34; color: #ffffff; } .cursor { position: absolute; top: 0; left: 0; width: 20px; height: 20px; background-color: #61dafb; border-radius: 50%; pointer-events: none; transition: transform 0.2s ease-out; will-change: transform; } .cursor-trail { position: absolute; top: 0; left: 0; width: 20px; height: 20px; background-color: rgba(97, 218, 251, 0.3); border-radius: 50%; pointer-events: none; transition: transform 0.4s ease-out; will-change: transform; } .emoji { position: absolute; top: 0; left: 0; font-size: 20px; pointer-events: none; transition: transform 0.2s ease-out; will-change: transform; } </style> </head> <body> <div class="cursor" id="cursor"></div> <div class="cursor-trail" id="cursorTrail"></div> <div class="emoji" id="emoji"></div> <script> const cursor = document.getElementById('cursor'); const cursorTrail = document.getElementById('cursorTrail'); const emoji = document.getElementById('emoji'); let mouseX = 0; let mouseY = 0; let trailX = 0; let trailY = 0; let emojiX = 0; let emojiY = 0; document.addEventListener('mousemove', e => { mouseX = e.clientX; mouseY = e.clientY; }); function animate() { trailX += (mouseX - trailX) * 0.15; trailY += (mouseY - trailY) * 0.15; emojiX += (mouseX - emojiX) * 0.1; emojiY += (mouseY - emojiY) * 0.1; cursor.style.transform = `translate(${mouseX - cursor.offsetWidth / 2}px, ${mouseY - cursor.offsetHeight / 2}px)`; cursorTrail.style.transform = `translate(${trailX - cursorTrail.offsetWidth / 2}px, ${trailY - cursorTrail.offsetHeight / 2}px)`; emoji.style.transform = `translate(${emojiX - emoji.offsetWidth / 2}px, ${emojiY - emoji.offsetHeight / 2}px)`; requestAnimationFrame(animate); } animate(); </script> </body> </html>