An open API service indexing awesome lists of open source software.

https://github.com/lostisworld/astro-magneto

Let an element follow the mouse cursor with a graceful and smooth motion.
https://github.com/lostisworld/astro-magneto

astro astro-component intersectionobserver magnet movement transform3d typescript

Last synced: 6 months ago
JSON representation

Let an element follow the mouse cursor with a graceful and smooth motion.

Awesome Lists containing this project

README

          

![github-image-magneto-min](https://user-images.githubusercontent.com/83787591/221999916-7684851f-19ba-47a8-9aeb-43b15faa3764.jpg)

# Astro Magneto
Let an element follow the mouse cursor with a graceful and smooth motion.

### [Live Demo](https://stackblitz.com/edit/withastro-astro-hjhuav?file=src%2Fpages%2Findex.astro)

## Instalation
> using npm
```
npm install astro-magneto
```
> using pnpm
```
pnpm add astro-magneto
```

## Possible Props
If Visual Studio Code is your preferred IDE, simply press CRTL+SPACE / CMD+SPACE to reveal the valid properties.
- **class** [sting]
- **options** [object]
- **transition** [object]

| Property | Object | Type | Default | Desctription |
| ------------------ | :-------: | :---------------: | :-----: | ---------------------------------------------------- |
| class | - | string | - | Add classes to the element |
| triggerArea | options | number | 100 | Element follows the mouse cursor in this range (around the element) |
| movementRatio | options | 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 | 0.5 | The triggerArea size directly affects the element's movement area, determining the space in which the element can be repositioned. |
| rootMargin | options | string | 0px | IntersectionObserver rootMargin option |
| threshold | options | number | 0.5 | IntersectionObserver threshold option |
| duration | transition | string | 250ms | Element speed to base position |
| timing | transition | string | ease | Transition timing function |
| delay | transition | string | 0s | This specifies the duration to wait before the element goes back to the base position |

## How to use
```html
---
import { Magneto } from 'astro-magneto';
---



Click Me



Click Me



Click Me



```

> Keep in mind that Magneto use the mousemove event, if the element is in the given (rootMargin, threashold) range.
> Additionally, the mousemove event will be automatically disabled once the element moves out of the viewport.