Motion+

Magnetic filings

An example of creating a grid of metal filings that rotate to point towards the cursor position using Motion for React.

Time
5 min
Difficulty
Intermediate
Access
Motion+
>Live exampleOpen in new tab

Introduction

This example shows how to create a grid of metal filings that rotate to point towards the cursor position. Each filing calculates the angle to the cursor and uses spring animations for smooth rotation.

In this tutorial, we'll learn to use the usePointerPosition hook from Motion+ to track cursor position, and the useTransform hook to calculate angles between elements.