Image Cursor Trail
光标图像拖尾
Small project images appear in order along the path of the pointer and quickly fade.
Where to use it
Show a sequence of project images in a portfolio, fashion, or photography intro. Space out image appearances by pointer travel and reuse a small set of lightweight thumbnails.
Practical example
A photographer uses a sequence of recent stills on the portfolio cover. A quick sweep reveals a short trail, which fades away before the next gesture.
Also called
- Image Trail
- Hover Image Trail
AI prompt
Add an Image Cursor Trail to [gallery hero]. As the pointer moves, a short sequence of project images appears along the path and fades. Cap the number of visible images and keep them clear of the foreground controls. Provide a still arrangement for reduced motion.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Image Cursor Trail</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.demo { background: radial-gradient(ellipse at 47% 23%, #3e3b4b, #181822 83%); }
.gallery {
position: relative;
display: block;
overflow: hidden;
width: min(100%, 365px);
height: min(72vh, 187px);
border: 1px solid #cfc6e849;
border-radius: 13px;
background: radial-gradient(circle, #dbdaeb50 1px, transparent 1.3px) 50% 50% / 18px 18px, #191920;
cursor: crosshair;
}
.gallery img {
position: absolute;
width: clamp(51px, 23%, 87px);
aspect-ratio: 1.25;
border: 2px solid #fff2dd;
border-radius: 4px;
box-shadow: 2px 6px 13px #0008;
object-fit: cover;
pointer-events: none;
}
.gallery-samples { transition: opacity .18s ease; }
.gallery[data-tracing] .gallery-samples { opacity: .18; }
.gallery-samples img { top: 50%; left: 50%; }
.gallery-samples img:nth-child(1) { transform: translate(-111%, -55%) rotate(-17deg); }
.gallery-samples img:nth-child(2) { transform: translate(-52%, -65%) rotate(4deg); }
.gallery-samples img:nth-child(3) { transform: translate(14%, -35%) rotate(14deg); }
.gallery-trail img { top: var(--y); left: var(--x); }
@media (prefers-reduced-motion: reduce) { .gallery-samples { transition: none; } }
</style>
</head>
<body>
<main class="demo">
<button class="gallery" type="button" aria-label="Move or tap to show the image trail">
<span class="gallery-samples" aria-hidden="true"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23f7dba2%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23f89764%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2284%22%20cy%3D%2225%22%20r%3D%2212%22%20fill%3D%22%23f7dba2%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23f89764%22%20d%3D%22M0%2074Q24%2010%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23823743%22%20d%3D%22M0%2062Q20%2038%2046%2043T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23521938%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23f7dba2%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E" alt=""><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23c3f0ef%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%2397ceeb%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2232%22%20cy%3D%2227%22%20r%3D%2214%22%20fill%3D%22%23c3f0ef%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%2397ceeb%22%20d%3D%22M0%2074Q24%2014%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%234c60af%22%20d%3D%22M0%2062Q20%2038%2046%2047T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%2321244b%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23c3f0ef%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E" alt=""><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23e0efb4%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%238cad6c%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2284%22%20cy%3D%2229%22%20r%3D%2216%22%20fill%3D%22%23e0efb4%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%238cad6c%22%20d%3D%22M0%2074Q24%2018%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23426f52%22%20d%3D%22M0%2062Q20%2038%2046%2051T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23223e33%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23e0efb4%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E" alt=""></span>
<span class="gallery-trail" aria-hidden="true"><img alt="" hidden><img alt="" hidden><img alt="" hidden><img alt="" hidden><img alt="" hidden></span>
</button>
</main>
<script>
const gallery = document.querySelector('.gallery');
const images = ["data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23f7dba2%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23f89764%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2284%22%20cy%3D%2225%22%20r%3D%2212%22%20fill%3D%22%23f7dba2%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23f89764%22%20d%3D%22M0%2074Q24%2010%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23823743%22%20d%3D%22M0%2062Q20%2038%2046%2043T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23521938%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23f7dba2%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E","data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23c3f0ef%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%2397ceeb%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2232%22%20cy%3D%2227%22%20r%3D%2214%22%20fill%3D%22%23c3f0ef%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%2397ceeb%22%20d%3D%22M0%2074Q24%2014%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%234c60af%22%20d%3D%22M0%2062Q20%2038%2046%2047T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%2321244b%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23c3f0ef%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E","data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23e0efb4%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%238cad6c%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2284%22%20cy%3D%2229%22%20r%3D%2216%22%20fill%3D%22%23e0efb4%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%238cad6c%22%20d%3D%22M0%2074Q24%2018%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23426f52%22%20d%3D%22M0%2062Q20%2038%2046%2051T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23223e33%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23e0efb4%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E","data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23e7d5f8%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23b186db%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2232%22%20cy%3D%2231%22%20r%3D%2212%22%20fill%3D%22%23e7d5f8%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23b186db%22%20d%3D%22M0%2074Q24%2022%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23754497%22%20d%3D%22M0%2062Q20%2038%2046%2055T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%2344244f%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23e7d5f8%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E","data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20120%2096%22%3E%0A%20%20%3Cdefs%3E%3ClinearGradient%20id%3D%22sky%22%20x2%3D%220%22%20y2%3D%221%22%20gradientUnits%3D%22objectBoundingBox%22%3E%3Cstop%20stop-color%3D%22%23f5c9b6%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23da886e%22%2F%3E%3C%2FlinearGradient%3E%3Cpattern%20id%3D%22paper%22%20width%3D%224%22%20height%3D%224%22%20patternUnits%3D%22userSpaceOnUse%22%3E%3Cpath%20d%3D%22M0%201h1m2%202h1%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.19%22%2F%3E%3C%2Fpattern%3E%3C%2Fdefs%3E%0A%20%20%3Cpath%20fill%3D%22url(%23sky)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%20%20%3Ccircle%20cx%3D%2284%22%20cy%3D%2233%22%20r%3D%2214%22%20fill%3D%22%23f5c9b6%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23da886e%22%20d%3D%22M0%2074Q24%2026%2054%2049t66-17v64H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%239c5b68%22%20d%3D%22M0%2062Q20%2038%2046%2059T120%2048v48H0z%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22%23512e51%22%20d%3D%22M0%2084q31-32%2066-7t54-10v29H0z%22%2F%3E%0A%20%20%3Cpath%20d%3D%22M0%2073q25-28%2046-10t74-2M0%2081q24-27%2048-13t72-2%22%20fill%3D%22none%22%20stroke%3D%22%23f5c9b6%22%20stroke-opacity%3D%22.46%22%20stroke-width%3D%22.65%22%2F%3E%0A%20%20%3Cpath%20fill%3D%22url(%23paper)%22%20d%3D%22M0%200h120v96H0z%22%2F%3E%0A%3C%2Fsvg%3E"];
const samples = [...gallery.querySelectorAll('.gallery-samples img')];
const trail = [...gallery.querySelectorAll('.gallery-trail img')];
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
let imageIndex = 0;
let lastX = -100;
let lastY = -100;
let lastTime = -100;
let restTimer;
let replayTimers = [];
function stamp(x, y) {
const box = gallery.getBoundingClientRect();
const margin = Math.min(44, box.width * .13);
const index = imageIndex++ % images.length;
const tile = trail[index];
tile.getAnimations().forEach((animation) => animation.cancel());
tile.src = images[index];
tile.style.setProperty('--x', Math.max(margin, Math.min(box.width - margin, x)) + 'px');
tile.style.setProperty('--y', Math.max(margin, Math.min(box.height - margin, y)) + 'px');
tile.style.zIndex = String(imageIndex);
tile.hidden = false;
const rotation = (index - 2) * 7;
const animation = tile.animate([
{ opacity: 0, transform: 'translate(-50%, -46%) rotate(' + rotation + 'deg) scale(.82)' },
{ opacity: 1, transform: 'translate(-50%, -50%) rotate(' + rotation + 'deg) scale(1)', offset: .19 },
{ opacity: 1, transform: 'translate(-50%, -50%) rotate(' + rotation + 'deg) scale(1)', offset: .52 },
{ opacity: 0, transform: 'translate(-50%, -26%) rotate(' + (rotation + 8) + 'deg) scale(.87)' },
], { duration: 740, easing: 'ease-out', fill: 'forwards' });
animation.onfinish = () => {
tile.hidden = true;
animation.cancel();
};
gallery.setAttribute('data-tracing', '');
clearTimeout(restTimer);
restTimer = setTimeout(() => gallery.removeAttribute('data-tracing'), 740);
}
function move(event) {
if (reducedMotion.matches || event.pointerType === 'touch') return;
const box = gallery.getBoundingClientRect();
const x = event.clientX - box.left;
const y = event.clientY - box.top;
if (Math.hypot(x - lastX, y - lastY) < 28 || event.timeStamp - lastTime < 46) return;
stamp(x, y);
lastX = x;
lastY = y;
lastTime = event.timeStamp;
}
function clearReplay() {
for (const timer of replayTimers) clearTimeout(timer);
replayTimers = [];
}
gallery.addEventListener('pointermove', move);
gallery.addEventListener('pointerleave', () => { lastX = -100; lastY = -100; });
gallery.addEventListener('click', (event) => {
if (reducedMotion.matches) {
imageIndex += 1;
samples.forEach((image, index) => { image.src = images[(index + imageIndex) % images.length]; });
return;
}
if (event.detail !== 0 && event.pointerType === 'mouse') {
const box = gallery.getBoundingClientRect();
stamp(event.clientX - box.left, event.clientY - box.top);
return;
}
clearReplay();
const box = gallery.getBoundingClientRect();
replayTimers = [0, 1, 2, 3, 4].map((step) => setTimeout(() => {
stamp(box.width * (.22 + step * .14), box.height * (.63 - Math.sin(step * .67) * .21));
}, 90 * step));
});
reducedMotion.addEventListener('change', () => {
clearReplay();
clearTimeout(restTimer);
gallery.removeAttribute('data-tracing');
for (const tile of trail) {
tile.getAnimations().forEach((animation) => animation.cancel());
tile.hidden = true;
}
});
</script>
</body>
</html>Original example by UI Skills