Image Trail
Area tempat gambar, kartu, atau emoji muncul di sepanjang jalur kursor lalu memudar, mengecil, berputar, atau menumpuk. Bisa menggambar jejaknya sendiri.
Move your cursor here
Color cards follow the pointer and fade away
Move your cursor here
Color cards follow the pointer and fade away
Move your cursor here
Color cards follow the pointer and fade away
Move your cursor here
Color cards follow the pointer and fade away
Move your cursor here
Color cards follow the pointer and fade away
@php
$area = 'grid h-72 content-center justify-items-center rounded-xl border border-line bg-subtle p-6 text-center';
$cards = [
'block h-20 w-16 rounded-lg bg-primary',
'block h-20 w-16 rounded-lg bg-success',
'block h-20 w-16 rounded-lg bg-warning',
'block h-20 w-16 rounded-lg bg-danger',
'block h-20 w-16 rounded-lg bg-primary-soft',
];
$title = 'text-lg font-semibold text-ink';
$hint = 'mt-1 text-sm text-muted';
@endphp
<x-markas.image-trail :class="$area">
<x-slot:items>
@foreach ($cards as $card)
<span class="{{ $card }}"></span>
@endforeach
</x-slot:items>
<p class="{{ $title }}">Move your cursor here</p>
<p class="{{ $hint }}">Color cards follow the pointer and fade away</p>
</x-markas.image-trail>import { ImageTrail } from "@/components/markas/ImageTrail";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-subtle p-6 text-center";
const cards = [
"block h-20 w-16 rounded-lg bg-primary",
"block h-20 w-16 rounded-lg bg-success",
"block h-20 w-16 rounded-lg bg-warning",
"block h-20 w-16 rounded-lg bg-danger",
"block h-20 w-16 rounded-lg bg-primary-soft",
];
const title = "text-lg font-semibold text-ink";
const hint = "mt-1 text-sm text-muted";
export default function ImageTrailExample() {
return (
<ImageTrail
className={area}
items={cards.map((card) => (
<span key={card} className={card}></span>
))}
>
<p className={title}>Move your cursor here</p>
<p className={hint}>Color cards follow the pointer and fade away</p>
</ImageTrail>
);
}<script setup lang="ts">
import ImageTrail from "@/components/markas/ImageTrail.vue";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-subtle p-6 text-center";
const cards = [
"block h-20 w-16 rounded-lg bg-primary",
"block h-20 w-16 rounded-lg bg-success",
"block h-20 w-16 rounded-lg bg-warning",
"block h-20 w-16 rounded-lg bg-danger",
"block h-20 w-16 rounded-lg bg-primary-soft",
];
const title = "text-lg font-semibold text-ink";
const hint = "mt-1 text-sm text-muted";
</script>
<template>
<ImageTrail :class="area">
<template #items>
<span v-for="card in cards" :key="card" :class="card"></span>
</template>
<p :class="title">Move your cursor here</p>
<p :class="hint">Color cards follow the pointer and fade away</p>
</ImageTrail>
</template><script lang="ts">
import ImageTrail from "$lib/components/markas/ImageTrail.svelte";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-subtle p-6 text-center";
const cards = [
"block h-20 w-16 rounded-lg bg-primary",
"block h-20 w-16 rounded-lg bg-success",
"block h-20 w-16 rounded-lg bg-warning",
"block h-20 w-16 rounded-lg bg-danger",
"block h-20 w-16 rounded-lg bg-primary-soft",
];
const title = "text-lg font-semibold text-ink";
const hint = "mt-1 text-sm text-muted";
</script>
<ImageTrail class={area}>
{#snippet items()}
{#each cards as card (card)}<span class={card}></span>{/each}
{/snippet}
<p class={title}>Move your cursor here</p>
<p class={hint}>Color cards follow the pointer and fade away</p>
</ImageTrail>---
import ImageTrail from "@/components/markas/ImageTrail.astro";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-subtle p-6 text-center";
const cards = [
"block h-20 w-16 rounded-lg bg-primary",
"block h-20 w-16 rounded-lg bg-success",
"block h-20 w-16 rounded-lg bg-warning",
"block h-20 w-16 rounded-lg bg-danger",
"block h-20 w-16 rounded-lg bg-primary-soft",
];
const title = "text-lg font-semibold text-ink";
const hint = "mt-1 text-sm text-muted";
---
<ImageTrail class={area}>
<Fragment slot="items">
{cards.map((card) => (<span class={card}></span>))}
</Fragment>
<p class={title}>Move your cursor here</p>
<p class={hint}>Color cards follow the pointer and fade away</p>
</ImageTrail>import { Component } from "@angular/core";
import { ImageTrail } from "./markas/image-trail.component";
@Component({
selector: "markas-example",
imports: [ImageTrail],
template: `
<markas-image-trail [class]="area">
<ng-container items>
@for (card of cards; track card) {
<span [class]="card"></span>
}
</ng-container>
<p [class]="title">Move your cursor here</p>
<p [class]="hint">Color cards follow the pointer and fade away</p>
</markas-image-trail>
`,
})
export default class ImageTrailExample {
protected readonly area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-subtle p-6 text-center";
protected readonly cards = [
"block h-20 w-16 rounded-lg bg-primary",
"block h-20 w-16 rounded-lg bg-success",
"block h-20 w-16 rounded-lg bg-warning",
"block h-20 w-16 rounded-lg bg-danger",
"block h-20 w-16 rounded-lg bg-primary-soft",
];
protected readonly title = "text-lg font-semibold text-ink";
protected readonly hint = "mt-1 text-sm text-muted";
}Contoh
Promo pasar kuliner dengan emoji
Jl. Braga, Bandung
Weekend street food market
40 stalls, Saturday and Sunday from 4 pm
Jl. Braga, Bandung
Weekend street food market
40 stalls, Saturday and Sunday from 4 pm
Jl. Braga, Bandung
Weekend street food market
40 stalls, Saturday and Sunday from 4 pm
Jl. Braga, Bandung
Weekend street food market
40 stalls, Saturday and Sunday from 4 pm
Jl. Braga, Bandung
Weekend street food market
40 stalls, Saturday and Sunday from 4 pm
@php
$area = 'grid h-72 content-center justify-items-start gap-3 rounded-xl bg-primary-soft p-8';
$emoji = 'block text-4xl';
$foods = ['🍜', '🍢', '🌶️', '🥥', '🍌'];
$eyebrow = 'text-sm font-medium text-primary';
$title = 'max-w-64 text-2xl font-semibold text-ink';
$hint = 'text-sm text-muted';
@endphp
<x-markas.image-trail variant="scale" :threshold="32" :class="$area">
<x-slot:items>
@foreach ($foods as $food)
<span class="{{ $emoji }}">{{ $food }}</span>
@endforeach
</x-slot:items>
<p class="{{ $eyebrow }}">Jl. Braga, Bandung</p>
<h3 class="{{ $title }}">Weekend street food market</h3>
<p class="{{ $hint }}">40 stalls, Saturday and Sunday from 4 pm</p>
<x-markas.button>See the stalls</x-markas.button>
</x-markas.image-trail>import { Button } from "@/components/markas/Button";
import { ImageTrail } from "@/components/markas/ImageTrail";
const area =
"grid h-72 content-center justify-items-start gap-3 rounded-xl bg-primary-soft p-8";
const emoji = "block text-4xl";
const foods = ["🍜", "🍢", "🌶️", "🥥", "🍌"];
const eyebrow = "text-sm font-medium text-primary";
const title = "max-w-64 text-2xl font-semibold text-ink";
const hint = "text-sm text-muted";
export default function Example() {
return (
<ImageTrail
variant="scale"
threshold={32}
className={area}
items={foods.map((food) => (
<span key={food} className={emoji}>
{food}
</span>
))}
>
<p className={eyebrow}>Jl. Braga, Bandung</p>
<h3 className={title}>Weekend street food market</h3>
<p className={hint}>40 stalls, Saturday and Sunday from 4 pm</p>
<Button>See the stalls</Button>
</ImageTrail>
);
}<script setup lang="ts">
import Button from "@/components/markas/Button.vue";
import ImageTrail from "@/components/markas/ImageTrail.vue";
const area =
"grid h-72 content-center justify-items-start gap-3 rounded-xl bg-primary-soft p-8";
const emoji = "block text-4xl";
const foods = ["🍜", "🍢", "🌶️", "🥥", "🍌"];
const eyebrow = "text-sm font-medium text-primary";
const title = "max-w-64 text-2xl font-semibold text-ink";
const hint = "text-sm text-muted";
</script>
<template>
<ImageTrail variant="scale" :threshold="32" :class="area">
<template #items>
<span v-for="food in foods" :key="food" :class="emoji">{{ food }}</span>
</template>
<p :class="eyebrow">Jl. Braga, Bandung</p>
<h3 :class="title">Weekend street food market</h3>
<p :class="hint">40 stalls, Saturday and Sunday from 4 pm</p>
<Button>See the stalls</Button>
</ImageTrail>
</template><script lang="ts">
import Button from "$lib/components/markas/Button.svelte";
import ImageTrail from "$lib/components/markas/ImageTrail.svelte";
const area =
"grid h-72 content-center justify-items-start gap-3 rounded-xl bg-primary-soft p-8";
const emoji = "block text-4xl";
const foods = ["🍜", "🍢", "🌶️", "🥥", "🍌"];
const eyebrow = "text-sm font-medium text-primary";
const title = "max-w-64 text-2xl font-semibold text-ink";
const hint = "text-sm text-muted";
</script>
<ImageTrail variant="scale" threshold={32} class={area}>
{#snippet items()}
{#each foods as food (food)}<span class={emoji}>{food}</span>{/each}
{/snippet}
<p class={eyebrow}>Jl. Braga, Bandung</p>
<h3 class={title}>Weekend street food market</h3>
<p class={hint}>40 stalls, Saturday and Sunday from 4 pm</p>
<Button>See the stalls</Button>
</ImageTrail>---
import Button from "@/components/markas/Button.astro";
import ImageTrail from "@/components/markas/ImageTrail.astro";
const area =
"grid h-72 content-center justify-items-start gap-3 rounded-xl bg-primary-soft p-8";
const emoji = "block text-4xl";
const foods = ["🍜", "🍢", "🌶️", "🥥", "🍌"];
const eyebrow = "text-sm font-medium text-primary";
const title = "max-w-64 text-2xl font-semibold text-ink";
const hint = "text-sm text-muted";
---
<ImageTrail variant="scale" threshold={32} class={area}>
<Fragment slot="items">
{foods.map((food) => (<span class={emoji}>{food}</span>))}
</Fragment>
<p class={eyebrow}>Jl. Braga, Bandung</p>
<h3 class={title}>Weekend street food market</h3>
<p class={hint}>40 stalls, Saturday and Sunday from 4 pm</p>
<Button>See the stalls</Button>
</ImageTrail>import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { ImageTrail } from "./markas/image-trail.component";
@Component({
selector: "markas-example",
imports: [Button, ImageTrail],
template: `
<markas-image-trail variant="scale" [threshold]="32" [class]="area">
<ng-container items>
@for (food of foods; track food) {
<span [class]="emoji">{{ food }}</span>
}
</ng-container>
<p [class]="eyebrow">Jl. Braga, Bandung</p>
<h3 [class]="title">Weekend street food market</h3>
<p [class]="hint">40 stalls, Saturday and Sunday from 4 pm</p>
<button markas-button>See the stalls</button>
</markas-image-trail>
`,
})
export default class ImageTrailEmojiExample {
protected readonly area =
"grid h-72 content-center justify-items-start gap-3 rounded-xl bg-primary-soft p-8";
protected readonly emoji = "block text-4xl";
protected readonly foods = ["🍜", "🍢", "🌶️", "🥥", "🍌"];
protected readonly eyebrow = "text-sm font-medium text-primary";
protected readonly title = "max-w-64 text-2xl font-semibold text-ink";
protected readonly hint = "text-sm text-muted";
}Bagian tim dengan inisial bertumpuk
Meet the people behind Markas
Rania, Dimas, Sekar, and Bayu
Meet the people behind Markas
Rania, Dimas, Sekar, and Bayu
Meet the people behind Markas
Rania, Dimas, Sekar, and Bayu
Meet the people behind Markas
Rania, Dimas, Sekar, and Bayu
Meet the people behind Markas
Rania, Dimas, Sekar, and Bayu
@php
$area = 'grid h-72 content-center justify-items-center rounded-xl border border-line bg-surface p-6 text-center';
$people = [
['initials' => 'RP', 'avatar' => 'grid size-14 place-items-center rounded-full bg-primary text-base font-semibold text-on-primary'],
['initials' => 'DS', 'avatar' => 'grid size-14 place-items-center rounded-full bg-primary-soft text-base font-semibold text-primary'],
['initials' => 'SW', 'avatar' => 'grid size-14 place-items-center rounded-full border border-line bg-subtle text-base font-semibold text-ink'],
['initials' => 'BA', 'avatar' => 'grid size-14 place-items-center rounded-full bg-ink text-base font-semibold text-canvas'],
];
$title = 'text-xl font-semibold text-ink';
$names = 'mt-2 text-sm text-muted';
@endphp
<x-markas.image-trail variant="stack" :threshold="56" :max="6" :class="$area">
<x-slot:items>
@foreach ($people as $person)
<span class="{{ $person['avatar'] }}">{{ $person['initials'] }}</span>
@endforeach
</x-slot:items>
<h3 class="{{ $title }}">Meet the people behind Markas</h3>
<p class="{{ $names }}">Rania, Dimas, Sekar, and Bayu</p>
</x-markas.image-trail>import { ImageTrail } from "@/components/markas/ImageTrail";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-surface p-6 text-center";
const people = [
{
initials: "RP",
avatar:
"grid size-14 place-items-center rounded-full bg-primary text-base font-semibold text-on-primary",
},
{
initials: "DS",
avatar:
"grid size-14 place-items-center rounded-full bg-primary-soft text-base font-semibold text-primary",
},
{
initials: "SW",
avatar:
"grid size-14 place-items-center rounded-full border border-line bg-subtle text-base font-semibold text-ink",
},
{
initials: "BA",
avatar:
"grid size-14 place-items-center rounded-full bg-ink text-base font-semibold text-canvas",
},
];
const title = "text-xl font-semibold text-ink";
const names = "mt-2 text-sm text-muted";
export default function Example() {
return (
<ImageTrail
variant="stack"
threshold={56}
max={6}
className={area}
items={people.map((person) => (
<span key={person.initials} className={person.avatar}>
{person.initials}
</span>
))}
>
<h3 className={title}>Meet the people behind Markas</h3>
<p className={names}>Rania, Dimas, Sekar, and Bayu</p>
</ImageTrail>
);
}<script setup lang="ts">
import ImageTrail from "@/components/markas/ImageTrail.vue";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-surface p-6 text-center";
const people = [
{
initials: "RP",
avatar:
"grid size-14 place-items-center rounded-full bg-primary text-base font-semibold text-on-primary",
},
{
initials: "DS",
avatar:
"grid size-14 place-items-center rounded-full bg-primary-soft text-base font-semibold text-primary",
},
{
initials: "SW",
avatar:
"grid size-14 place-items-center rounded-full border border-line bg-subtle text-base font-semibold text-ink",
},
{
initials: "BA",
avatar:
"grid size-14 place-items-center rounded-full bg-ink text-base font-semibold text-canvas",
},
];
const title = "text-xl font-semibold text-ink";
const names = "mt-2 text-sm text-muted";
</script>
<template>
<ImageTrail variant="stack" :threshold="56" :max="6" :class="area">
<template #items>
<span
v-for="person in people"
:key="person.initials"
:class="person.avatar"
>{{ person.initials }}</span
>
</template>
<h3 :class="title">Meet the people behind Markas</h3>
<p :class="names">Rania, Dimas, Sekar, and Bayu</p>
</ImageTrail>
</template><script lang="ts">
import ImageTrail from "$lib/components/markas/ImageTrail.svelte";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-surface p-6 text-center";
const people = [
{
initials: "RP",
avatar:
"grid size-14 place-items-center rounded-full bg-primary text-base font-semibold text-on-primary",
},
{
initials: "DS",
avatar:
"grid size-14 place-items-center rounded-full bg-primary-soft text-base font-semibold text-primary",
},
{
initials: "SW",
avatar:
"grid size-14 place-items-center rounded-full border border-line bg-subtle text-base font-semibold text-ink",
},
{
initials: "BA",
avatar:
"grid size-14 place-items-center rounded-full bg-ink text-base font-semibold text-canvas",
},
];
const title = "text-xl font-semibold text-ink";
const names = "mt-2 text-sm text-muted";
</script>
<ImageTrail variant="stack" threshold={56} max={6} class={area}>
{#snippet items()}
{#each people as person (person.initials)}<span class={person.avatar}
>{person.initials}</span
>{/each}
{/snippet}
<h3 class={title}>Meet the people behind Markas</h3>
<p class={names}>Rania, Dimas, Sekar, and Bayu</p>
</ImageTrail>---
import ImageTrail from "@/components/markas/ImageTrail.astro";
const area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-surface p-6 text-center";
const people = [
{
initials: "RP",
avatar:
"grid size-14 place-items-center rounded-full bg-primary text-base font-semibold text-on-primary",
},
{
initials: "DS",
avatar:
"grid size-14 place-items-center rounded-full bg-primary-soft text-base font-semibold text-primary",
},
{
initials: "SW",
avatar:
"grid size-14 place-items-center rounded-full border border-line bg-subtle text-base font-semibold text-ink",
},
{
initials: "BA",
avatar:
"grid size-14 place-items-center rounded-full bg-ink text-base font-semibold text-canvas",
},
];
const title = "text-xl font-semibold text-ink";
const names = "mt-2 text-sm text-muted";
---
<ImageTrail variant="stack" threshold={56} max={6} class={area}>
<Fragment slot="items">
{people.map((person) => (<span class={person.avatar}>{person.initials}</span>))}
</Fragment>
<h3 class={title}>Meet the people behind Markas</h3>
<p class={names}>Rania, Dimas, Sekar, and Bayu</p>
</ImageTrail>import { Component } from "@angular/core";
import { ImageTrail } from "./markas/image-trail.component";
@Component({
selector: "markas-example",
imports: [ImageTrail],
template: `
<markas-image-trail
variant="stack"
[threshold]="56"
[max]="6"
[class]="area"
>
<ng-container items>
@for (person of people; track person.initials) {
<span [class]="person.avatar">{{ person.initials }}</span>
}
</ng-container>
<h3 [class]="title">Meet the people behind Markas</h3>
<p [class]="names">Rania, Dimas, Sekar, and Bayu</p>
</markas-image-trail>
`,
})
export default class ImageTrailTeamExample {
protected readonly area =
"grid h-72 content-center justify-items-center rounded-xl border border-line bg-surface p-6 text-center";
protected readonly people = [
{
initials: "RP",
avatar:
"grid size-14 place-items-center rounded-full bg-primary text-base font-semibold text-on-primary",
},
{
initials: "DS",
avatar:
"grid size-14 place-items-center rounded-full bg-primary-soft text-base font-semibold text-primary",
},
{
initials: "SW",
avatar:
"grid size-14 place-items-center rounded-full border border-line bg-subtle text-base font-semibold text-ink",
},
{
initials: "BA",
avatar:
"grid size-14 place-items-center rounded-full bg-ink text-base font-semibold text-canvas",
},
];
protected readonly title = "text-xl font-semibold text-ink";
protected readonly names = "mt-2 text-sm text-muted";
}Ajakan harga dengan autoplay
Plans from Rp 49.000 a month
Every plan includes all three frameworks
Plans from Rp 49.000 a month
Every plan includes all three frameworks
Plans from Rp 49.000 a month
Every plan includes all three frameworks
Plans from Rp 49.000 a month
Every plan includes all three frameworks
Plans from Rp 49.000 a month
Every plan includes all three frameworks
@php
$area = 'grid h-64 content-center justify-items-center rounded-xl bg-ink p-6 text-center text-canvas';
$chip = 'block rounded-full border border-line bg-surface px-3 py-1 text-sm font-medium whitespace-nowrap text-ink';
$perks = ['Rp 49.000', 'Free for 14 days', 'Rp 149.000', 'Cancel anytime'];
$title = 'text-2xl font-semibold';
$hint = 'mt-1 mb-4 text-sm text-canvas/70';
@endphp
<x-markas.image-trail variant="rotate" :threshold="48" :duration="1000" autoplay :class="$area">
<x-slot:items>
@foreach ($perks as $perk)
<span class="{{ $chip }}">{{ $perk }}</span>
@endforeach
</x-slot:items>
<h3 class="{{ $title }}">Plans from Rp 49.000 a month</h3>
<p class="{{ $hint }}">Every plan includes all three frameworks</p>
<x-markas.button>Start free trial</x-markas.button>
</x-markas.image-trail>import { Button } from "@/components/markas/Button";
import { ImageTrail } from "@/components/markas/ImageTrail";
const area =
"grid h-64 content-center justify-items-center rounded-xl bg-ink p-6 text-center text-canvas";
const chip =
"block rounded-full border border-line bg-surface px-3 py-1 text-sm font-medium whitespace-nowrap text-ink";
const perks = ["Rp 49.000", "Free for 14 days", "Rp 149.000", "Cancel anytime"];
const title = "text-2xl font-semibold";
const hint = "mt-1 mb-4 text-sm text-canvas/70";
export default function Example() {
return (
<ImageTrail
variant="rotate"
threshold={48}
duration={1000}
autoplay
className={area}
items={perks.map((perk) => (
<span key={perk} className={chip}>
{perk}
</span>
))}
>
<h3 className={title}>Plans from Rp 49.000 a month</h3>
<p className={hint}>Every plan includes all three frameworks</p>
<Button>Start free trial</Button>
</ImageTrail>
);
}<script setup lang="ts">
import Button from "@/components/markas/Button.vue";
import ImageTrail from "@/components/markas/ImageTrail.vue";
const area =
"grid h-64 content-center justify-items-center rounded-xl bg-ink p-6 text-center text-canvas";
const chip =
"block rounded-full border border-line bg-surface px-3 py-1 text-sm font-medium whitespace-nowrap text-ink";
const perks = ["Rp 49.000", "Free for 14 days", "Rp 149.000", "Cancel anytime"];
const title = "text-2xl font-semibold";
const hint = "mt-1 mb-4 text-sm text-canvas/70";
</script>
<template>
<ImageTrail
variant="rotate"
:threshold="48"
:duration="1000"
autoplay
:class="area"
>
<template #items>
<span v-for="perk in perks" :key="perk" :class="chip">{{ perk }}</span>
</template>
<h3 :class="title">Plans from Rp 49.000 a month</h3>
<p :class="hint">Every plan includes all three frameworks</p>
<Button>Start free trial</Button>
</ImageTrail>
</template><script lang="ts">
import Button from "$lib/components/markas/Button.svelte";
import ImageTrail from "$lib/components/markas/ImageTrail.svelte";
const area =
"grid h-64 content-center justify-items-center rounded-xl bg-ink p-6 text-center text-canvas";
const chip =
"block rounded-full border border-line bg-surface px-3 py-1 text-sm font-medium whitespace-nowrap text-ink";
const perks = [
"Rp 49.000",
"Free for 14 days",
"Rp 149.000",
"Cancel anytime",
];
const title = "text-2xl font-semibold";
const hint = "mt-1 mb-4 text-sm text-canvas/70";
</script>
<ImageTrail
variant="rotate"
threshold={48}
duration={1000}
autoplay
class={area}
>
{#snippet items()}
{#each perks as perk (perk)}<span class={chip}>{perk}</span>{/each}
{/snippet}
<h3 class={title}>Plans from Rp 49.000 a month</h3>
<p class={hint}>Every plan includes all three frameworks</p>
<Button>Start free trial</Button>
</ImageTrail>---
import Button from "@/components/markas/Button.astro";
import ImageTrail from "@/components/markas/ImageTrail.astro";
const area =
"grid h-64 content-center justify-items-center rounded-xl bg-ink p-6 text-center text-canvas";
const chip =
"block rounded-full border border-line bg-surface px-3 py-1 text-sm font-medium whitespace-nowrap text-ink";
const perks = ["Rp 49.000", "Free for 14 days", "Rp 149.000", "Cancel anytime"];
const title = "text-2xl font-semibold";
const hint = "mt-1 mb-4 text-sm text-canvas/70";
---
<ImageTrail variant="rotate" threshold={48} duration={1000} autoplay class={area}>
<Fragment slot="items">
{perks.map((perk) => (<span class={chip}>{perk}</span>))}
</Fragment>
<h3 class={title}>Plans from Rp 49.000 a month</h3>
<p class={hint}>Every plan includes all three frameworks</p>
<Button>Start free trial</Button>
</ImageTrail>import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { ImageTrail } from "./markas/image-trail.component";
@Component({
selector: "markas-example",
imports: [Button, ImageTrail],
template: `
<markas-image-trail
variant="rotate"
[threshold]="48"
[duration]="1000"
autoplay
[class]="area"
>
<ng-container items>
@for (perk of perks; track perk) {
<span [class]="chip">{{ perk }}</span>
}
</ng-container>
<h3 [class]="title">Plans from Rp 49.000 a month</h3>
<p [class]="hint">Every plan includes all three frameworks</p>
<button markas-button>Start free trial</button>
</markas-image-trail>
`,
})
export default class ImageTrailPricingExample {
protected readonly area =
"grid h-64 content-center justify-items-center rounded-xl bg-ink p-6 text-center text-canvas";
protected readonly chip =
"block rounded-full border border-line bg-surface px-3 py-1 text-sm font-medium whitespace-nowrap text-ink";
protected readonly perks = [
"Rp 49.000",
"Free for 14 days",
"Rp 149.000",
"Cancel anytime",
];
protected readonly title = "text-2xl font-semibold";
protected readonly hint = "mt-1 mb-4 text-sm text-canvas/70";
}Instalasi
npx markasui@latest add image-trailpnpm dlx markasui@latest add image-trailyarn dlx markasui@latest add image-trailbunx --bun markasui@latest add image-trail- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Pasang dependensi:
npm install alpinejs - Salin source komponen di bawah ini ke
resources/views/components/markas/image-trail.blade.php.
@props([
'threshold' => 40,
'variant' => 'fade',
'max' => 12,
'duration' => 800,
'autoplay' => false,
])
@php
$base = 'relative isolate overflow-hidden';
$layerClass = 'pointer-events-none absolute inset-0 -z-10 [&>*]:absolute [&>*]:-translate-x-1/2 [&>*]:-translate-y-1/2 [&>*]:opacity-0 motion-reduce:hidden';
$dotClass = 'block size-4 rounded-full bg-primary';
$items = $__laravel_slots['items'] ?? null;
$options = [
'threshold' => (float) $threshold,
'variant' => in_array($variant, ['fade', 'scale', 'rotate', 'stack'], true) ? $variant : 'fade',
'max' => (int) $max,
'duration' => (float) $duration,
'autoplay' => (bool) $autoplay,
];
@endphp
{{-- Clones the next item to the pointer once it has travelled `threshold` px. At most `max` clones live at once. --}}
<div
x-data="{
stop: null,
frames(variant, n) {
const turn = ((n * 47) % 70) - 35;
if (variant === 'scale') return [{ opacity: 1, transform: 'scale(0)' }, { opacity: 1, transform: 'scale(1)', offset: 0.25 }, { opacity: 0, transform: 'scale(0.2)' }];
if (variant === 'rotate') return [{ opacity: 0, transform: `rotate(${turn}deg) scale(.6)` }, { opacity: 1, transform: `rotate(${turn / 2}deg) scale(1)`, offset: 0.2 }, { opacity: 0, transform: 'rotate(0deg) translateY(32px) scale(.9)' }];
if (variant === 'stack') return [{ opacity: 0, transform: `rotate(${turn / 3}deg) scale(1.4)` }, { opacity: 1, transform: `rotate(${turn / 3}deg) scale(1)` }];
return [{ opacity: 1 }, { opacity: 0 }];
},
init() {
const { threshold, variant, max, duration, autoplay } = @js($options);
const root = this.$root;
const source = this.$refs.source;
const layer = this.$refs.layer;
const still = () => window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
let last = null;
let count = 0;
let inside = false;
const spawn = (x, y) => {
const items = source.children;
if (! items.length) return;
if (last && Math.hypot(x - last.x, y - last.y) < threshold) return;
last = { x, y };
if (layer.children.length >= max) layer.firstElementChild?.remove();
const item = items[count % items.length].cloneNode(true);
item.style.left = `${x}px`;
item.style.top = `${y}px`;
layer.append(item);
const stack = variant === 'stack';
const animation = item.animate?.(this.frames(variant, count), { duration: stack ? duration * 0.4 : duration, easing: 'cubic-bezier(.2,.7,.3,1)', fill: 'forwards' });
if (animation && ! stack) animation.onfinish = () => item.remove();
count++;
};
const move = (event) => {
if (still()) return;
inside = true;
const rect = root.getBoundingClientRect();
spawn(event.clientX - rect.left, event.clientY - rect.top);
};
const leave = () => {
inside = false;
last = null;
if (variant !== 'stack') return;
for (const item of [...layer.children]) {
const out = item.animate?.([{ opacity: 1 }, { opacity: 0 }], { duration: 300, fill: 'forwards' });
if (out) out.onfinish = () => item.remove();
else item.remove();
}
};
root.addEventListener('pointermove', move);
root.addEventListener('pointerleave', leave);
{{-- Autoplay: a figure-eight trail while visible, the tab is shown, and the pointer is elsewhere. --}}
let frame = 0;
let observer = null;
let sync = null;
if (autoplay && ! still() && typeof IntersectionObserver === 'function') {
let seen = false;
const run = (now) => {
if (! inside) {
const t = now / 1100;
const { width, height } = root.getBoundingClientRect();
spawn(width * (0.5 + 0.36 * Math.sin(t)), height * (0.5 + 0.3 * Math.sin(2 * t)));
}
frame = requestAnimationFrame(run);
};
sync = () => {
cancelAnimationFrame(frame);
if (seen && ! document.hidden) frame = requestAnimationFrame(run);
};
observer = new IntersectionObserver(([entry]) => {
seen = Boolean(entry?.isIntersecting);
sync();
});
observer.observe(root);
document.addEventListener('visibilitychange', sync);
}
this.stop = () => {
root.removeEventListener('pointermove', move);
root.removeEventListener('pointerleave', leave);
observer?.disconnect();
if (sync) document.removeEventListener('visibilitychange', sync);
cancelAnimationFrame(frame);
layer.replaceChildren();
};
},
destroy() {
this.stop?.();
},
}"
{{ $attributes->class([$base]) }}
>
<div x-ref="source" hidden>
@if ($items)
{{ $items }}
@else
<span class="{{ $dotClass }}"></span>
@endif
</div>
<div x-ref="layer" aria-hidden="true" class="{{ $layerClass }}"></div>
{{ $slot }}
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/ImageTrail.tsx.
"use client";
import { useEffect, useRef, type ComponentProps, type ReactNode } from "react";
export type ImageTrailVariant = "fade" | "scale" | "rotate" | "stack";
const base = "relative isolate overflow-hidden";
const layerClass =
"pointer-events-none absolute inset-0 -z-10 [&>*]:absolute [&>*]:-translate-x-1/2 [&>*]:-translate-y-1/2 [&>*]:opacity-0 motion-reduce:hidden";
const dotClass = "block size-4 rounded-full bg-primary";
const cx = (...c: (string | false | null | undefined)[]) =>
c.filter(Boolean).join(" ");
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
type Frame = { opacity: number; transform?: string; offset?: number };
/** Keyframes per variant. The angle comes from the trail counter, so every run looks the same. */
function frames(variant: ImageTrailVariant, n: number): Frame[] {
const turn = ((n * 47) % 70) - 35;
if (variant === "scale")
return [
{ opacity: 1, transform: "scale(0)" },
{ opacity: 1, transform: "scale(1)", offset: 0.25 },
{ opacity: 0, transform: "scale(0.2)" },
];
if (variant === "rotate")
return [
{ opacity: 0, transform: `rotate(${turn}deg) scale(.6)` },
{ opacity: 1, transform: `rotate(${turn / 2}deg) scale(1)`, offset: 0.2 },
{ opacity: 0, transform: "rotate(0deg) translateY(32px) scale(.9)" },
];
if (variant === "stack")
return [
{ opacity: 0, transform: `rotate(${turn / 3}deg) scale(1.4)` },
{ opacity: 1, transform: `rotate(${turn / 3}deg) scale(1)` },
];
return [{ opacity: 1 }, { opacity: 0 }];
}
type TrailOptions = {
threshold: number;
variant: ImageTrailVariant;
max: number;
duration: number;
autoplay: boolean;
};
/** Run `tick` on every frame while the element is on screen and the tab is visible. */
function whileVisible(element: Element, tick: (now: number) => void) {
let frame = 0;
let seen = false;
const run = (now: number) => {
tick(now);
frame = requestAnimationFrame(run);
};
const sync = () => {
cancelAnimationFrame(frame);
if (seen && !document.hidden) frame = requestAnimationFrame(run);
};
const observer = new IntersectionObserver(([entry]) => {
seen = Boolean(entry?.isIntersecting);
sync();
});
observer.observe(element);
document.addEventListener("visibilitychange", sync);
return () => {
observer.disconnect();
document.removeEventListener("visibilitychange", sync);
cancelAnimationFrame(frame);
};
}
/** Clone the next item to (x, y) once the pointer has travelled `threshold` px. At most `max` clones live at once. */
function createTrail(
root: HTMLElement,
source: HTMLElement,
layer: HTMLElement,
options: TrailOptions,
) {
const { threshold, variant, max, duration } = options;
let last: { x: number; y: number } | null = null;
let count = 0;
let inside = false;
const spawn = (x: number, y: number) => {
const items = source.children;
if (!items.length) return;
if (last && Math.hypot(x - last.x, y - last.y) < threshold) return;
last = { x, y };
if (layer.children.length >= max) layer.firstElementChild?.remove();
const item = items[count % items.length]!.cloneNode(true) as HTMLElement;
item.style.left = `${x}px`;
item.style.top = `${y}px`;
layer.append(item);
const stack = variant === "stack";
const animation = item.animate?.(frames(variant, count), {
duration: stack ? duration * 0.4 : duration,
easing: "cubic-bezier(.2,.7,.3,1)",
fill: "forwards",
});
if (animation && !stack) animation.onfinish = () => item.remove();
count++;
};
const move = (event: PointerEvent) => {
if (still()) return;
inside = true;
const rect = root.getBoundingClientRect();
spawn(event.clientX - rect.left, event.clientY - rect.top);
};
const leave = () => {
inside = false;
last = null;
if (variant !== "stack") return;
for (const item of [...layer.children]) {
const out = item.animate?.([{ opacity: 1 }, { opacity: 0 }], {
duration: 300,
fill: "forwards",
});
if (out) out.onfinish = () => item.remove();
else item.remove();
}
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
const stopAuto =
options.autoplay && !still() && typeof IntersectionObserver === "function"
? whileVisible(root, (now) => {
if (inside) return;
const t = now / 1100;
const { width, height } = root.getBoundingClientRect();
spawn(
width * (0.5 + 0.36 * Math.sin(t)),
height * (0.5 + 0.3 * Math.sin(2 * t)),
);
})
: null;
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
stopAuto?.();
layer.replaceChildren();
};
}
export type ImageTrailProps = ComponentProps<"div"> & {
/** Elements that appear along the trail, cloned in order. A small primary dot when empty. */
items?: ReactNode;
/** Distance in px the pointer travels before the next item appears. */
threshold?: number;
/** How each item enters and leaves. */
variant?: ImageTrailVariant;
/** Most items on screen at once. */
max?: number;
/** Life of one item in ms. */
duration?: number;
/** Draws a figure-eight trail on its own while visible and the pointer is elsewhere. */
autoplay?: boolean;
};
export function ImageTrail({
items,
threshold = 40,
variant = "fade",
max = 12,
duration = 800,
autoplay = false,
className,
children,
...props
}: ImageTrailProps) {
const rootRef = useRef<HTMLDivElement>(null);
const sourceRef = useRef<HTMLDivElement>(null);
const layerRef = useRef<HTMLDivElement>(null);
useEffect(
() =>
createTrail(rootRef.current!, sourceRef.current!, layerRef.current!, {
threshold,
variant,
max,
duration,
autoplay,
}),
[threshold, variant, max, duration, autoplay],
);
return (
<div {...props} ref={rootRef} className={cx(base, className)}>
<div ref={sourceRef} hidden>
{items ?? <span className={dotClass}></span>}
</div>
<div ref={layerRef} aria-hidden="true" className={layerClass}></div>
{children}
</div>
);
}- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/ImageTrail.vue.
<script setup lang="ts">
import { onBeforeUnmount, onMounted, useTemplateRef, watch } from "vue";
export type ImageTrailVariant = "fade" | "scale" | "rotate" | "stack";
const props = withDefaults(
defineProps<{
/** Distance in px the pointer travels before the next item appears. */
threshold?: number;
/** How each item enters and leaves. */
variant?: ImageTrailVariant;
/** Most items on screen at once. */
max?: number;
/** Life of one item in ms. */
duration?: number;
/** Draws a figure-eight trail on its own while visible and the pointer is elsewhere. */
autoplay?: boolean;
}>(),
{
threshold: 40,
variant: "fade",
max: 12,
duration: 800,
autoplay: false,
},
);
const base = "relative isolate overflow-hidden";
const layerClass =
"pointer-events-none absolute inset-0 -z-10 [&>*]:absolute [&>*]:-translate-x-1/2 [&>*]:-translate-y-1/2 [&>*]:opacity-0 motion-reduce:hidden";
const dotClass = "block size-4 rounded-full bg-primary";
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
type Frame = { opacity: number; transform?: string; offset?: number };
/** Keyframes per variant. The angle comes from the trail counter, so every run looks the same. */
function frames(variant: ImageTrailVariant, n: number): Frame[] {
const turn = ((n * 47) % 70) - 35;
if (variant === "scale")
return [
{ opacity: 1, transform: "scale(0)" },
{ opacity: 1, transform: "scale(1)", offset: 0.25 },
{ opacity: 0, transform: "scale(0.2)" },
];
if (variant === "rotate")
return [
{ opacity: 0, transform: `rotate(${turn}deg) scale(.6)` },
{ opacity: 1, transform: `rotate(${turn / 2}deg) scale(1)`, offset: 0.2 },
{ opacity: 0, transform: "rotate(0deg) translateY(32px) scale(.9)" },
];
if (variant === "stack")
return [
{ opacity: 0, transform: `rotate(${turn / 3}deg) scale(1.4)` },
{ opacity: 1, transform: `rotate(${turn / 3}deg) scale(1)` },
];
return [{ opacity: 1 }, { opacity: 0 }];
}
/** Run `tick` on every frame while the element is on screen and the tab is visible. */
function whileVisible(element: Element, tick: (now: number) => void) {
let frame = 0;
let seen = false;
const run = (now: number) => {
tick(now);
frame = requestAnimationFrame(run);
};
const sync = () => {
cancelAnimationFrame(frame);
if (seen && !document.hidden) frame = requestAnimationFrame(run);
};
const observer = new IntersectionObserver(([entry]) => {
seen = Boolean(entry?.isIntersecting);
sync();
});
observer.observe(element);
document.addEventListener("visibilitychange", sync);
return () => {
observer.disconnect();
document.removeEventListener("visibilitychange", sync);
cancelAnimationFrame(frame);
};
}
const rootEl = useTemplateRef<HTMLDivElement>("rootRef");
const sourceEl = useTemplateRef<HTMLDivElement>("sourceRef");
const layerEl = useTemplateRef<HTMLDivElement>("layerRef");
/** Clone the next item to (x, y) once the pointer has travelled `threshold` px. At most `max` clones live at once. */
function createTrail(
root: HTMLElement,
source: HTMLElement,
layer: HTMLElement,
) {
const { threshold, variant, max, duration } = props;
let last: { x: number; y: number } | null = null;
let count = 0;
let inside = false;
const spawn = (x: number, y: number) => {
const items = source.children;
if (!items.length) return;
if (last && Math.hypot(x - last.x, y - last.y) < threshold) return;
last = { x, y };
if (layer.children.length >= max) layer.firstElementChild?.remove();
const item = items[count % items.length]!.cloneNode(true) as HTMLElement;
item.style.left = `${x}px`;
item.style.top = `${y}px`;
layer.append(item);
const stack = variant === "stack";
const animation = item.animate?.(frames(variant, count), {
duration: stack ? duration * 0.4 : duration,
easing: "cubic-bezier(.2,.7,.3,1)",
fill: "forwards",
});
if (animation && !stack) animation.onfinish = () => item.remove();
count++;
};
const move = (event: PointerEvent) => {
if (still()) return;
inside = true;
const rect = root.getBoundingClientRect();
spawn(event.clientX - rect.left, event.clientY - rect.top);
};
const leave = () => {
inside = false;
last = null;
if (variant !== "stack") return;
for (const item of [...layer.children]) {
const out = item.animate?.([{ opacity: 1 }, { opacity: 0 }], {
duration: 300,
fill: "forwards",
});
if (out) out.onfinish = () => item.remove();
else item.remove();
}
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
const stopAuto =
props.autoplay && !still() && typeof IntersectionObserver === "function"
? whileVisible(root, (now) => {
if (inside) return;
const t = now / 1100;
const { width, height } = root.getBoundingClientRect();
spawn(
width * (0.5 + 0.36 * Math.sin(t)),
height * (0.5 + 0.3 * Math.sin(2 * t)),
);
})
: null;
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
stopAuto?.();
layer.replaceChildren();
};
}
let stop = () => {};
const start = () => {
stop();
stop = createTrail(rootEl.value!, sourceEl.value!, layerEl.value!);
};
onMounted(start);
watch(
() => [
props.threshold,
props.variant,
props.max,
props.duration,
props.autoplay,
],
start,
);
onBeforeUnmount(() => stop());
</script>
<template>
<div ref="rootRef" :class="base">
<div ref="sourceRef" hidden>
<slot name="items"><span :class="dotClass"></span></slot>
</div>
<div ref="layerRef" aria-hidden="true" :class="layerClass"></div>
<slot />
</div>
</template>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/lib/components/markas/ImageTrail.svelte.
<script lang="ts">
import type { Snippet } from "svelte";
import type { HTMLAttributes } from "svelte/elements";
type ImageTrailVariant = "fade" | "scale" | "rotate" | "stack";
const base = "relative isolate overflow-hidden";
const layerClass =
"pointer-events-none absolute inset-0 -z-10 [&>*]:absolute [&>*]:-translate-x-1/2 [&>*]:-translate-y-1/2 [&>*]:opacity-0 motion-reduce:hidden";
const dotClass = "block size-4 rounded-full bg-primary";
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
type Frame = { opacity: number; transform?: string; offset?: number };
/** Keyframes per variant. The angle comes from the trail counter, so every run looks the same. */
function frames(variant: ImageTrailVariant, n: number): Frame[] {
const turn = ((n * 47) % 70) - 35;
if (variant === "scale")
return [
{ opacity: 1, transform: "scale(0)" },
{ opacity: 1, transform: "scale(1)", offset: 0.25 },
{ opacity: 0, transform: "scale(0.2)" },
];
if (variant === "rotate")
return [
{ opacity: 0, transform: `rotate(${turn}deg) scale(.6)` },
{
opacity: 1,
transform: `rotate(${turn / 2}deg) scale(1)`,
offset: 0.2,
},
{ opacity: 0, transform: "rotate(0deg) translateY(32px) scale(.9)" },
];
if (variant === "stack")
return [
{ opacity: 0, transform: `rotate(${turn / 3}deg) scale(1.4)` },
{ opacity: 1, transform: `rotate(${turn / 3}deg) scale(1)` },
];
return [{ opacity: 1 }, { opacity: 0 }];
}
type TrailOptions = {
threshold: number;
variant: ImageTrailVariant;
max: number;
duration: number;
autoplay: boolean;
};
/** Run `tick` on every frame while the element is on screen and the tab is visible. */
function whileVisible(element: Element, tick: (now: number) => void) {
let frame = 0;
let seen = false;
const run = (now: number) => {
tick(now);
frame = requestAnimationFrame(run);
};
const sync = () => {
cancelAnimationFrame(frame);
if (seen && !document.hidden) frame = requestAnimationFrame(run);
};
const observer = new IntersectionObserver(([entry]) => {
seen = Boolean(entry?.isIntersecting);
sync();
});
observer.observe(element);
document.addEventListener("visibilitychange", sync);
return () => {
observer.disconnect();
document.removeEventListener("visibilitychange", sync);
cancelAnimationFrame(frame);
};
}
/** Clone the next item to (x, y) once the pointer has travelled `threshold` px. At most `max` clones live at once. */
function createTrail(
root: HTMLElement,
source: HTMLElement,
layer: HTMLElement,
options: TrailOptions,
) {
const { threshold, variant, max, duration } = options;
let last: { x: number; y: number } | null = null;
let count = 0;
let inside = false;
const spawn = (x: number, y: number) => {
const items = source.children;
if (!items.length) return;
if (last && Math.hypot(x - last.x, y - last.y) < threshold) return;
last = { x, y };
if (layer.children.length >= max) layer.firstElementChild?.remove();
const item = items[count % items.length]!.cloneNode(true) as HTMLElement;
item.style.left = `${x}px`;
item.style.top = `${y}px`;
layer.append(item);
const stack = variant === "stack";
const animation = item.animate?.(frames(variant, count), {
duration: stack ? duration * 0.4 : duration,
easing: "cubic-bezier(.2,.7,.3,1)",
fill: "forwards",
});
if (animation && !stack) animation.onfinish = () => item.remove();
count++;
};
const move = (event: PointerEvent) => {
if (still()) return;
inside = true;
const rect = root.getBoundingClientRect();
spawn(event.clientX - rect.left, event.clientY - rect.top);
};
const leave = () => {
inside = false;
last = null;
if (variant !== "stack") return;
for (const item of [...layer.children]) {
const out = item.animate?.([{ opacity: 1 }, { opacity: 0 }], {
duration: 300,
fill: "forwards",
});
if (out) out.onfinish = () => item.remove();
else item.remove();
}
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
const stopAuto =
options.autoplay && !still() && typeof IntersectionObserver === "function"
? whileVisible(root, (now) => {
if (inside) return;
const t = now / 1100;
const { width, height } = root.getBoundingClientRect();
spawn(
width * (0.5 + 0.36 * Math.sin(t)),
height * (0.5 + 0.3 * Math.sin(2 * t)),
);
})
: null;
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
stopAuto?.();
layer.replaceChildren();
};
}
type Props = HTMLAttributes<HTMLDivElement> & {
/** Elements that appear along the trail, cloned in order. A small primary dot when empty. */
items?: Snippet;
/** Distance in px the pointer travels before the next item appears. */
threshold?: number;
/** How each item enters and leaves. */
variant?: ImageTrailVariant;
/** Most items on screen at once. */
max?: number;
/** Life of one item in ms. */
duration?: number;
/** Draws a figure-eight trail on its own while visible and the pointer is elsewhere. */
autoplay?: boolean;
children?: Snippet;
};
let {
items,
threshold = 40,
variant = "fade",
max = 12,
duration = 800,
autoplay = false,
class: className,
children,
...rest
}: Props = $props();
let root = $state<HTMLDivElement>();
let source = $state<HTMLDivElement>();
let layer = $state<HTMLDivElement>();
$effect(() => {
const options = { threshold, variant, max, duration, autoplay };
if (root && source && layer)
return createTrail(root, source, layer, options);
});
</script>
<div {...rest} bind:this={root} class={[base, className]}>
<div bind:this={source} hidden>
{#if items}{@render items()}{:else}<span class={dotClass}></span>{/if}
</div>
<div bind:this={layer} aria-hidden="true" class={layerClass}></div>
{@render children?.()}
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/ImageTrail.astro.
---
import type { HTMLAttributes } from "astro/types";
type ImageTrailVariant = "fade" | "scale" | "rotate" | "stack";
const base = "relative isolate overflow-hidden";
const layerClass =
"pointer-events-none absolute inset-0 -z-10 [&>*]:absolute [&>*]:-translate-x-1/2 [&>*]:-translate-y-1/2 [&>*]:opacity-0 motion-reduce:hidden";
const dotClass = "block size-4 rounded-full bg-primary";
type Props = HTMLAttributes<"div"> & {
/** Distance in px the pointer travels before the next item appears. */
threshold?: number;
/** How each item enters and leaves. */
variant?: ImageTrailVariant;
/** Most items on screen at once. */
max?: number;
/** Life of one item in ms. */
duration?: number;
/** Draws a figure-eight trail on its own while visible and the pointer is elsewhere. */
autoplay?: boolean;
};
const {
threshold = 40,
variant = "fade",
max = 12,
duration = 800,
autoplay = false,
class: className,
...rest
} = Astro.props;
const options = JSON.stringify({
threshold: Number(threshold),
variant,
max: Number(max),
duration: Number(duration),
autoplay: Boolean(autoplay),
});
---
<markas-image-trail class="contents" data-options={options}>
<div {...rest} class:list={[base, className]}>
<div hidden><slot name="items"><span class={dotClass}></span></slot></div>
<div aria-hidden="true" class={layerClass}></div>
<slot />
</div>
</markas-image-trail>
<script>
type ImageTrailVariant = "fade" | "scale" | "rotate" | "stack";
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
type Frame = { opacity: number; transform?: string; offset?: number };
/** Keyframes per variant. The angle comes from the trail counter, so every run looks the same. */
function frames(variant: ImageTrailVariant, n: number): Frame[] {
const turn = ((n * 47) % 70) - 35;
if (variant === "scale")
return [
{ opacity: 1, transform: "scale(0)" },
{ opacity: 1, transform: "scale(1)", offset: 0.25 },
{ opacity: 0, transform: "scale(0.2)" },
];
if (variant === "rotate")
return [
{ opacity: 0, transform: `rotate(${turn}deg) scale(.6)` },
{ opacity: 1, transform: `rotate(${turn / 2}deg) scale(1)`, offset: 0.2 },
{ opacity: 0, transform: "rotate(0deg) translateY(32px) scale(.9)" },
];
if (variant === "stack")
return [
{ opacity: 0, transform: `rotate(${turn / 3}deg) scale(1.4)` },
{ opacity: 1, transform: `rotate(${turn / 3}deg) scale(1)` },
];
return [{ opacity: 1 }, { opacity: 0 }];
}
type TrailOptions = {
threshold: number;
variant: ImageTrailVariant;
max: number;
duration: number;
autoplay: boolean;
};
/** Run `tick` on every frame while the element is on screen and the tab is visible. */
function whileVisible(element: Element, tick: (now: number) => void) {
let frame = 0;
let seen = false;
const run = (now: number) => {
tick(now);
frame = requestAnimationFrame(run);
};
const sync = () => {
cancelAnimationFrame(frame);
if (seen && !document.hidden) frame = requestAnimationFrame(run);
};
const observer = new IntersectionObserver(([entry]) => {
seen = Boolean(entry?.isIntersecting);
sync();
});
observer.observe(element);
document.addEventListener("visibilitychange", sync);
return () => {
observer.disconnect();
document.removeEventListener("visibilitychange", sync);
cancelAnimationFrame(frame);
};
}
/** Clone the next item to (x, y) once the pointer has travelled `threshold` px. At most `max` clones live at once. */
function createTrail(
root: HTMLElement,
source: HTMLElement,
layer: HTMLElement,
options: TrailOptions,
) {
const { threshold, variant, max, duration } = options;
let last: { x: number; y: number } | null = null;
let count = 0;
let inside = false;
const spawn = (x: number, y: number) => {
const items = source.children;
if (!items.length) return;
if (last && Math.hypot(x - last.x, y - last.y) < threshold) return;
last = { x, y };
if (layer.children.length >= max) layer.firstElementChild?.remove();
const item = items[count % items.length]!.cloneNode(true) as HTMLElement;
item.style.left = `${x}px`;
item.style.top = `${y}px`;
layer.append(item);
const stack = variant === "stack";
const animation = item.animate?.(frames(variant, count), {
duration: stack ? duration * 0.4 : duration,
easing: "cubic-bezier(.2,.7,.3,1)",
fill: "forwards",
});
if (animation && !stack) animation.onfinish = () => item.remove();
count++;
};
const move = (event: PointerEvent) => {
if (still()) return;
inside = true;
const rect = root.getBoundingClientRect();
spawn(event.clientX - rect.left, event.clientY - rect.top);
};
const leave = () => {
inside = false;
last = null;
if (variant !== "stack") return;
for (const item of [...layer.children]) {
const out = item.animate?.([{ opacity: 1 }, { opacity: 0 }], {
duration: 300,
fill: "forwards",
});
if (out) out.onfinish = () => item.remove();
else item.remove();
}
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
const stopAuto =
options.autoplay && !still() && typeof IntersectionObserver === "function"
? whileVisible(root, (now) => {
if (inside) return;
const t = now / 1100;
const { width, height } = root.getBoundingClientRect();
spawn(
width * (0.5 + 0.36 * Math.sin(t)),
height * (0.5 + 0.3 * Math.sin(2 * t)),
);
})
: null;
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
stopAuto?.();
layer.replaceChildren();
};
}
// Per instance: each area follows its own pointer and runs its own autoplay loop.
class ImageTrail extends HTMLElement {
#stop = () => {};
connectedCallback() {
const root = this.firstElementChild as HTMLElement | null;
const [source, layer] = (root?.children ?? []) as HTMLCollectionOf<HTMLElement>;
if (!root || !source || !layer) return;
this.#stop = createTrail(
root,
source,
layer,
JSON.parse(this.dataset.options ?? "{}") as TrailOptions,
);
}
disconnectedCallback() {
this.#stop();
}
}
if (!customElements.get("markas-image-trail"))
customElements.define("markas-image-trail", ImageTrail);
</script>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/app/markas/image-trail.component.ts.
import {
afterRenderEffect,
booleanAttribute,
ChangeDetectionStrategy,
Component,
computed,
type ElementRef,
input,
numberAttribute,
viewChild,
} from "@angular/core";
export type ImageTrailVariant = "fade" | "scale" | "rotate" | "stack";
const base = "relative isolate overflow-hidden";
const layerClass =
"pointer-events-none absolute inset-0 -z-10 [&>*]:absolute [&>*]:-translate-x-1/2 [&>*]:-translate-y-1/2 [&>*]:opacity-0 motion-reduce:hidden";
const dotClass = "block size-4 rounded-full bg-primary";
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
type Frame = { opacity: number; transform?: string; offset?: number };
/** Keyframes per variant. The angle comes from the trail counter, so every run looks the same. */
function frames(variant: ImageTrailVariant, n: number): Frame[] {
const turn = ((n * 47) % 70) - 35;
if (variant === "scale")
return [
{ opacity: 1, transform: "scale(0)" },
{ opacity: 1, transform: "scale(1)", offset: 0.25 },
{ opacity: 0, transform: "scale(0.2)" },
];
if (variant === "rotate")
return [
{ opacity: 0, transform: `rotate(${turn}deg) scale(.6)` },
{ opacity: 1, transform: `rotate(${turn / 2}deg) scale(1)`, offset: 0.2 },
{ opacity: 0, transform: "rotate(0deg) translateY(32px) scale(.9)" },
];
if (variant === "stack")
return [
{ opacity: 0, transform: `rotate(${turn / 3}deg) scale(1.4)` },
{ opacity: 1, transform: `rotate(${turn / 3}deg) scale(1)` },
];
return [{ opacity: 1 }, { opacity: 0 }];
}
type TrailOptions = {
threshold: number;
variant: ImageTrailVariant;
max: number;
duration: number;
autoplay: boolean;
};
/** Run `tick` on every frame while the element is on screen and the tab is visible. */
function whileVisible(element: Element, tick: (now: number) => void) {
let frame = 0;
let seen = false;
const run = (now: number) => {
tick(now);
frame = requestAnimationFrame(run);
};
const sync = () => {
cancelAnimationFrame(frame);
if (seen && !document.hidden) frame = requestAnimationFrame(run);
};
const observer = new IntersectionObserver(([entry]) => {
seen = Boolean(entry?.isIntersecting);
sync();
});
observer.observe(element);
document.addEventListener("visibilitychange", sync);
return () => {
observer.disconnect();
document.removeEventListener("visibilitychange", sync);
cancelAnimationFrame(frame);
};
}
/** Clone the next item to (x, y) once the pointer has travelled `threshold` px. At most `max` clones live at once. */
function createTrail(
root: HTMLElement,
source: HTMLElement,
layer: HTMLElement,
options: TrailOptions,
) {
const { threshold, variant, max, duration } = options;
let last: { x: number; y: number } | null = null;
let count = 0;
let inside = false;
const spawn = (x: number, y: number) => {
const items = source.children;
if (!items.length) return;
if (last && Math.hypot(x - last.x, y - last.y) < threshold) return;
last = { x, y };
if (layer.children.length >= max) layer.firstElementChild?.remove();
const item = items[count % items.length]!.cloneNode(true) as HTMLElement;
item.style.left = `${x}px`;
item.style.top = `${y}px`;
layer.append(item);
const stack = variant === "stack";
const animation = item.animate?.(frames(variant, count), {
duration: stack ? duration * 0.4 : duration,
easing: "cubic-bezier(.2,.7,.3,1)",
fill: "forwards",
});
if (animation && !stack) animation.onfinish = () => item.remove();
count++;
};
const move = (event: PointerEvent) => {
if (still()) return;
inside = true;
const rect = root.getBoundingClientRect();
spawn(event.clientX - rect.left, event.clientY - rect.top);
};
const leave = () => {
inside = false;
last = null;
if (variant !== "stack") return;
for (const item of [...layer.children]) {
const out = item.animate?.([{ opacity: 1 }, { opacity: 0 }], {
duration: 300,
fill: "forwards",
});
if (out) out.onfinish = () => item.remove();
else item.remove();
}
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
const stopAuto =
options.autoplay && !still() && typeof IntersectionObserver === "function"
? whileVisible(root, (now) => {
if (inside) return;
const t = now / 1100;
const { width, height } = root.getBoundingClientRect();
spawn(
width * (0.5 + 0.36 * Math.sin(t)),
height * (0.5 + 0.3 * Math.sin(2 * t)),
);
})
: null;
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
stopAuto?.();
layer.replaceChildren();
};
}
/**
* Slots: an element with the `items` attribute (an ng-container works) holds the elements cloned
* along the trail; everything else is the content. The host stays out of layout; the user's class
* lands on the area.
*/
@Component({
selector: "markas-image-trail",
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: "contents" },
template: `
<div #rootEl [class]="classes()">
<div #sourceEl hidden>
<ng-content select="[items]"
><span [class]="dotClass"></span
></ng-content>
</div>
<div #layerEl aria-hidden="true" [class]="layerClass"></div>
<ng-content />
</div>
`,
})
export class ImageTrail {
/** Distance in px the pointer travels before the next item appears. */
readonly threshold = input(40, { transform: numberAttribute });
/** How each item enters and leaves. */
readonly variant = input<ImageTrailVariant>("fade");
/** Most items on screen at once. */
readonly max = input(12, { transform: numberAttribute });
/** Life of one item in ms. */
readonly duration = input(800, { transform: numberAttribute });
/** Draws a figure-eight trail on its own while visible and the pointer is elsewhere. */
readonly autoplay = input(false, { transform: booleanAttribute });
readonly userClass = input("", { alias: "class" });
protected readonly dotClass = dotClass;
protected readonly layerClass = layerClass;
protected readonly classes = computed(() =>
[base, this.userClass()].filter(Boolean).join(" "),
);
private readonly root = viewChild.required<ElementRef<HTMLElement>>("rootEl");
private readonly source =
viewChild.required<ElementRef<HTMLElement>>("sourceEl");
private readonly layer =
viewChild.required<ElementRef<HTMLElement>>("layerEl");
constructor() {
afterRenderEffect((onCleanup) => {
const options = {
threshold: this.threshold(),
variant: this.variant(),
max: this.max(),
duration: this.duration(),
autoplay: this.autoplay(),
};
onCleanup(
createTrail(
this.root().nativeElement,
this.source().nativeElement,
this.layer().nativeElement,
options,
),
);
});
}
}Pemakaian
<x-markas.image-trail variant="scale" :threshold="48" class="grid h-72 place-items-center rounded-xl bg-subtle">
<x-slot:items>
<img src="/img/sepatu-1.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/sepatu-2.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/sepatu-3.webp" alt="" class="w-20 rounded-lg" />
</x-slot:items>
<h2 class="text-2xl font-semibold">Sneakers musim baru</h2>
</x-markas.image-trail>Butuh Alpine.js.
import { ImageTrail } from "@/components/markas/ImageTrail";
<ImageTrail
variant="scale"
threshold={48}
className="grid h-72 place-items-center rounded-xl bg-subtle"
items={
<>
<img src="/img/sepatu-1.webp" alt="" className="w-20 rounded-lg" />
<img src="/img/sepatu-2.webp" alt="" className="w-20 rounded-lg" />
<img src="/img/sepatu-3.webp" alt="" className="w-20 rounded-lg" />
</>
}
>
<h2 className="text-2xl font-semibold">Sneakers musim baru</h2>
</ImageTrail>;<template>
<ImageTrail
variant="scale"
:threshold="48"
class="grid h-72 place-items-center rounded-xl bg-subtle"
>
<template #items>
<img src="/img/sepatu-1.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/sepatu-2.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/sepatu-3.webp" alt="" class="w-20 rounded-lg" />
</template>
<h2 class="text-2xl font-semibold">Sneakers musim baru</h2>
</ImageTrail>
</template><script lang="ts">
import ImageTrail from "$lib/components/markas/ImageTrail.svelte";
</script>
<ImageTrail
variant="scale"
threshold={48}
class="grid h-72 place-items-center rounded-xl bg-subtle"
>
{#snippet items()}
<img src="/img/shoe-1.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/shoe-2.webp" alt="" class="w-20 rounded-lg" />
{/snippet}
<h2 class="text-2xl font-semibold">New season sneakers</h2>
</ImageTrail>---
import ImageTrail from "@/components/markas/ImageTrail.astro";
---
<ImageTrail
variant="scale"
threshold={48}
class="grid h-72 place-items-center rounded-xl bg-subtle"
>
<Fragment slot="items">
<img src="/img/shoe-1.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/shoe-2.webp" alt="" class="w-20 rounded-lg" />
</Fragment>
<h2 class="text-2xl font-semibold">New season sneakers</h2>
</ImageTrail>Satu script kecil yang dibundel menjalankan setiap jejak lewat elemen markas-image-trail.
import { Component } from "@angular/core";
import { ImageTrail } from "./markas/image-trail.component";
@Component({
selector: "app-sneakers",
imports: [ImageTrail],
template: `
<markas-image-trail
variant="scale"
[threshold]="48"
class="grid h-72 place-items-center rounded-xl bg-subtle"
>
<ng-container items>
<img src="/img/shoe-1.webp" alt="" class="w-20 rounded-lg" />
<img src="/img/shoe-2.webp" alt="" class="w-20 rounded-lg" />
</ng-container>
<h2 class="text-2xl font-semibold">New season sneakers</h2>
</markas-image-trail>
`,
})
export class Sneakers {}- Elemen digandakan bergantian ke posisi kursor setiap
thresholdpx. Paling banyakmaxsalinan hidup sekaligus dan yang selesai dihapus, sehingga DOM tetap kecil. variant:fade,scale,rotate(sudutnya mengikuti pola tetap, jadi setiap putaran terlihat sama), ataustack, tempat elemen menumpuk sampai kursor keluar.autoplaymenggambar jejak angka delapan selama area terlihat dan kursor di tempat lain. Berhenti saat area tergulir keluar atau tab disembunyikan.- Jejak berada di belakang konten dan bersifat aria-hidden. Dengan reduced motion tidak ada yang digambar. Atribut dan
classjatuh ke area itu sendiri.
Props
| Nama | Tipe | Default | Keterangan |
|---|---|---|---|
items | ReactNode / slot #items | primary dot | Elemen yang muncul di sepanjang jejak, digandakan bergantian. Gambar, kartu warna token, emoji, atau inisial. |
variant | "fade" | "scale" | "rotate" | "stack" | "fade" | fade: muncul lalu memudar. scale: membesar lalu mengecil. rotate: berputar masuk lalu jatuh sambil memudar. stack: menumpuk seperti foto sampai kursor keluar. |
threshold | number | 40 | Jarak dalam px yang ditempuh kursor sebelum elemen berikutnya muncul. Nilai besar membuat jejak lebih jarang. |
max | number | 12 | Jumlah elemen terbanyak di layar sekaligus. Yang paling lama dihapus lebih dulu, sehingga DOM tetap kecil. |
duration | number | 800 | Umur satu elemen dalam ms. Pada stack, elemen masuk dalam 40% waktu ini lalu bertahan sampai kursor keluar. |
autoplay | boolean | false | Menggambar jejak angka delapan sendiri selama area terlihat, tab aktif, dan kursor di tempat lain. Berguna di layar sentuh. |
children / slot | ReactNode / slot | - | Konten di atas jejak. Atur tata letaknya dengan class sendiri pada komponen (grid, tinggi, padding). |
Aksesibilitas
- Elemen jejak adalah salinan di dalam lapisan aria-hidden yang tidak menangkap pointer; elemen sumber ada di elemen hidden, jadi pembaca layar hanya membaca konten.
- Jejak berada di belakang konten, sehingga teks dan tombol tetap terbaca dan bisa diklik.
- Dengan reduced motion tidak ada jejak yang digambar dan autoplay tetap mati.
Komponen terkait
Komponen markasui lain dengan class yang sama di setiap framework.
- Bottom NavigationBar bawah gaya aplikasi mobile. Pill meluncur ke item terpilih, labelnya muncul, dan bar bisa menciut jadi ikon saat konten discroll.
- Card StackTumpukan kartu bertingkat. Geser, tombol panah, atau tombol navigasi membuang kartu teratas lalu kartu berikutnya naik. Berputar, dengan indikator posisi.
- Chat MessagePesan dalam percakapan AI. Gelembung user di kanan, balasan asisten dengan avatar, aksi saat hover, indikator mengetik, dan efek streaming token opsional.
- Currency InputKolom uang yang memformat saat mengetik (Rp 12.500.000), menjaga posisi kursor, dan mengirim angka murni. Opsional chip nominal cepat.
- DockDock ala macOS. Ikon membesar halus mengikuti kursor atau fokus, label muncul di atas, item terbuka bertitik, dan memantul saat dibuka.
- Drag ElementsArea kartu atau stiker yang bisa diseret dengan momentum ringan di dalam batasnya. Panah menggeser item yang fokus, Escape mengembalikannya.