1.0.0 • Published 1 year ago

astro-magneto v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

github-image-magneto-min

Astro Magneto

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

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.

PropertyObjectTypeDefaultDesctription
class-string-Add classes to the element
triggerAreaoptionsnumber100Element follows the mouse cursor in this range (around the element)
movementRatiooptions0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.80.5The triggerArea size directly affects the element's movement area, determining the space in which the element can be repositioned.
rootMarginoptionsstring0pxIntersectionObserver rootMargin option
thresholdoptionsnumber0.5IntersectionObserver threshold option
durationtransitionstring250msElement speed to base position
timingtransitionstringeaseTransition timing function
delaytransitionstringeaseTransition timing function

How to use

---
import { Magneto } from 'astro-magneto';
---

<div>

  <!-- basic -->
  <Magneto>
    <button type="button">Click Me</button>
  </Magneto>

  <!-- using class with tailwind -->
  <Magneto class="text-red-500">
    <button type="button">Click Me</button>
  </Magneto>

  <!-- using options -->
  <Magneto 
    options={{ 
      triggerArea: 200,
      movementRatio: 0.8,
      rootMargin: '100px 0px',
      threshold: 1
    }}
  >
    <button type="button">Click Me</button>
  </Magneto>

  <!-- using transition -->
  <Magneto 
    transition={{ 
      duration: '500ms',
      timing: 'linear',
      delay: '5s'
    }}
  >

</div>

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.