Magnetic Mouse Trails

Viscous fluid particles that exhibit magnetic attraction and smooth repulsions based on cursor movement.

Under the Hood: How it Works

Friction & Attraction Physics Vectors

These particles use two distinct physics rules. First: Magnetic repulsion via Math.atan2(dy, dx) pushes the particle away from the mouse. Second: An elastic attraction variable pulls the particle smoothly back to its original origin point. A low-opacity fillRect across the canvas ensures a gorgeous trailing burn-in effect.

Full Screen Preview Download HTML

Technical Details

Category Interactive
Technology canvas
Performance moderate
Interaction mouse-move

Tags

How to Use This Animation

Step-by-step instructions to integrate Magnetic Mouse Trails into your project.

🚀

Add Magnetic Mouse Trails to Your Site

  1. 1 Click Download HTML to get the standalone Magnetic Mouse Trails file
  2. 2 Open the file in a code editor and copy the <style> block into your CSS
  3. 3 Copy the <script> block before your closing </body> tag
  4. 4 Add the HTML markup to your page where you want the animation
🎯

Use as a Full-Page Background

  1. 1 Add a container div with position: fixed; inset: 0; z-index: -1
  2. 2 Place the animation inside that container
  3. 3 Your page content will appear above the animation
  4. 4 Add pointer-events: none to the container if the animation blocks clicks

Source Code
Source Copied!
Loved this effect? Host your deployment globally for free on our partner networks:
Vercel Netlify Hostinger