Spotlight card
A soft light follows the pointer across a card.
- enhancer
- card
- hover
- pointer
- glow
- since 0.1
Background Studio: tune it below, then copy the code
Your system asks for reduced motion: the demo shows its final state and nothing moves.
Live demo
Spotlight card example
Spotlight
Move the pointer over this card.
Spotlight
Move the pointer over this card.
Code
It follows the controls above: change an option and the code changes with it.
<link rel="stylesheet" href="/axi0/motion/motion.css?v=6">
<script src="/axi0/motion/motion.js?v=10" defer></script>
<div class="demo-card" data-motion="spotlight">
<h4>Spotlight</h4>
<p>Move the pointer over this card.</p>
</div>
import { Spotlight } from "./motion/react/Spotlight";
<Spotlight>Your content</Spotlight>
<script setup lang="ts">
import Spotlight from "./motion/vue/Spotlight.vue";
</script>
<template>
<Spotlight>Your content</Spotlight>
</template>
const el = document.querySelector("#title");
el.dataset.motion = "spotlight";
The wrappers: Spotlight.tsx (React, TypeScript) and Spotlight.vue (Vue). Both render the same attributes as the HTML; the loader does the rest.
Options
| Attribute | Default | What it does |
|---|---|---|
data-motion-color | auto | any CSS color, best with some transparency; auto is a soft orange glow |
data-motion-size | 280 | the light's radius in pixels |
Accessibility
It moves only with the pointer (no loop). Reduced motion: a still glow in the middle on hover. It uses the card's ::before and sets position: relative on it.
Size
spotlight.js is 0.6 KB gzip. A page loads the loader (2.7 KB) and core.js (1.4 KB) once, whatever it uses.