Skip to content

Commit 8ff9135

Browse files
committed
Viewport-aware slider preloading and edge fade gradients
Compute preload buffer dynamically from viewport width so all visible cards have images ready on any screen size. Add left/right gradient overlays to smoothly fade slider edges into the backdrop.
1 parent 35dc393 commit 8ff9135

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

frontend/src/lib/components/slider/WallpaperSlider.svelte

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,23 @@
9292
const CARD_MAX_HEIGHT = 250;
9393
const SKEW = 5;
9494
const EXTRACT_DEBOUNCE = 300;
95-
const BUFFER = 6;
95+
const MIN_BUFFER = 6;
9696
9797
let trackOffset = $derived(
9898
areaWidth / 2 - currentIndex * CARD_STEP - ACTIVE_WIDTH / 2
9999
);
100100
101+
let viewportBuffer = $derived(
102+
Math.max(
103+
MIN_BUFFER,
104+
Math.ceil((areaWidth / 2 + ACTIVE_WIDTH) / CARD_STEP) + 2
105+
)
106+
);
107+
101108
let visibleRange = $derived.by(() => {
102109
if (!areaWidth || items.length === 0) return {start: 0, end: 0};
103-
const halfViewport = areaWidth / 2 + ACTIVE_WIDTH;
104-
const cardsInHalf = Math.ceil(halfViewport / CARD_STEP) + 1;
105-
const start = Math.max(0, currentIndex - cardsInHalf - BUFFER);
106-
const end = Math.min(
107-
items.length,
108-
currentIndex + cardsInHalf + BUFFER + 1
109-
);
110+
const start = Math.max(0, currentIndex - viewportBuffer);
111+
const end = Math.min(items.length, currentIndex + viewportBuffer + 1);
110112
return {start, end};
111113
});
112114
@@ -240,7 +242,8 @@
240242
});
241243
242244
function preloadAround(idx: number) {
243-
for (let d = -BUFFER; d <= BUFFER; d++) {
245+
const buf = viewportBuffer;
246+
for (let d = -buf; d <= buf; d++) {
244247
const i = idx + d;
245248
if (i >= 0 && i < items.length && items[i].imagePath) {
246249
loadPreview(items[i].imagePath);
@@ -476,7 +479,7 @@
476479
</div>
477480
{:else if !isLoading && items.length > 0}
478481
<div
479-
class="flex w-full items-center overflow-hidden"
482+
class="relative flex w-full items-center overflow-hidden"
480483
style="height: {CARD_MAX_HEIGHT + 50}px"
481484
bind:clientWidth={areaWidth}
482485
>
@@ -583,6 +586,16 @@
583586
</button>
584587
{/each}
585588
</div>
589+
590+
<!-- Edge fade gradients -->
591+
<div
592+
class="pointer-events-none absolute inset-y-0 left-0 z-10"
593+
style="width: 220px; background: linear-gradient(to right, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.5) 40%, transparent 100%)"
594+
></div>
595+
<div
596+
class="pointer-events-none absolute inset-y-0 right-0 z-10"
597+
style="width: 220px; background: linear-gradient(to left, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.5) 40%, transparent 100%)"
598+
></div>
586599
</div>
587600

588601
{#if searchVisible}

0 commit comments

Comments
 (0)