Effects Fancy Stable

Magnetic

A generic wrapper that pulls its child toward the pointer once it enters an activation field larger than the child's own box, and springs back to rest the instant the pointer leaves — a fine-pointer affordance with no touch or keyboard equivalent

Preview

Installation

pnpm add fancy-ui-svelte
import { Magnetic } from 'fancy-ui-svelte'

Usage

svelte
<script lang="ts">
  import { Magnetic } from 'fancy-ui-svelte';
</script>

<Magnetic />

Examples

Basic Usage

A single outlined button that leans toward the cursor.

Strength

The same button at three pull strengths, side by side.

Props

PropTypeDefaultDescription
strength number0.35Pull multiplier applied to the pointer's offset from the child's centre.
radius number40Pixels the activation field extends beyond the outer element's own box, on every side. Also sizes the (transparent by default) `::before` halo.
max number24Per-axis clamp (px) on the translated offset — a hard travel cap independent of element geometry, radius, or strength.
disabled booleanfalseDisables the pull: no listeners are attached at all, and both translation vars are pinned at `0px`. Never touches the wrapped child's own `disabled` state.
class string-Additional CSS classes, merged onto the static outer wrapper.
ref HTMLDivElement | nullnullBindable reference to the outer (static, untransformed) wrapper element.

Slots

SlotDescription
childrenThe single wrapped element — a button, icon link, or card.