fix(site): keep carousel position during media load and clarify platform copy
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
const prev = root.querySelector('[data-carousel-prev]');
|
||||
const next = root.querySelector('[data-carousel-next]');
|
||||
const count = root.querySelector('[data-carousel-count]');
|
||||
let active = 0, fits = false, settle, dragging = null;
|
||||
let active = 0, fits = false, settle, dragging = null, layoutWidth = 0;
|
||||
const center = item => item.offsetLeft + item.offsetWidth / 2 - track.clientWidth / 2;
|
||||
function state() {
|
||||
prev.disabled = fits || active === 0;
|
||||
@@ -28,6 +28,10 @@
|
||||
}
|
||||
function layout() {
|
||||
const available = root.clientWidth;
|
||||
// Media already has a fixed aspect ratio. A load or height-only resize must
|
||||
// never interrupt native touch momentum or an in-flight smooth scroll.
|
||||
if (!available || available === layoutWidth) return;
|
||||
layoutWidth = available;
|
||||
const gap = parseFloat(getComputedStyle(track).columnGap) || 0;
|
||||
const width = items.reduce((sum, item) => sum + item.offsetWidth, 0) + gap * Math.max(0, items.length - 1);
|
||||
fits = width <= available - 32;
|
||||
@@ -69,7 +73,6 @@
|
||||
track.addEventListener('dragstart', event => event.preventDefault());
|
||||
// Prevent legacy page smooth-scroll from converting horizontal trackpad input.
|
||||
track.addEventListener('wheel', event => { if(Math.abs(event.deltaX)>Math.abs(event.deltaY)) event.stopPropagation(); },{passive:true});
|
||||
track.querySelectorAll('img,video').forEach(media=>media.addEventListener(media.tagName==='IMG'?'load':'loadedmetadata',layout));
|
||||
new ResizeObserver(layout).observe(root);
|
||||
const observer=new IntersectionObserver(entries=>entries.forEach(entry=>{if(!entry.isIntersecting)root.querySelectorAll('video').forEach(v=>v.pause());}));observer.observe(root);
|
||||
layout();
|
||||
|
||||
Reference in New Issue
Block a user