correct video element order

This commit is contained in:
Simon
2026-02-09 22:08:28 +00:00
parent 3d81b6aae7
commit 81597c3bb2
2 changed files with 39 additions and 6 deletions

View File

@@ -769,8 +769,11 @@ body.theme-light .setting-item select option {
/* Grid Container */ /* Grid Container */
.grid-container { .grid-container {
column-width: 260px; display: grid;
column-gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
grid-auto-rows: 10px;
gap: 16px;
align-items: start;
padding: 24px; padding: 24px;
max-width: var(--grid-max); max-width: var(--grid-max);
margin: 0 auto; margin: 0 auto;
@@ -778,8 +781,9 @@ body.theme-light .setting-item select option {
@media (max-width: 768px) { @media (max-width: 768px) {
.grid-container { .grid-container {
column-width: 160px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
column-gap: 12px; grid-auto-rows: 10px;
gap: 12px;
padding: 16px; padding: 16px;
} }
@@ -882,8 +886,7 @@ body.theme-light .setting-item select option {
border: 1px solid var(--border); border: 1px solid var(--border);
box-shadow: 0 6px 16px var(--shadow); box-shadow: 0 6px 16px var(--shadow);
position: relative; position: relative;
break-inside: avoid; margin-bottom: 0;
margin-bottom: 16px;
} }
.video-card:hover { .video-card:hover {

View File

@@ -140,6 +140,9 @@ App.videos = App.videos || {};
`; `;
const thumb = card.querySelector('img'); const thumb = card.querySelector('img');
App.videos.attachNoReferrerRetry(thumb); App.videos.attachNoReferrerRetry(thumb);
if (thumb) {
thumb.addEventListener('load', App.videos.scheduleMasonryLayout);
}
const favoriteBtn = card.querySelector('.favorite-btn'); const favoriteBtn = card.querySelector('.favorite-btn');
if (favoriteBtn && favoriteKey) { if (favoriteBtn && favoriteKey) {
App.favorites.setButtonState(favoriteBtn, favoritesSet.has(favoriteKey)); App.favorites.setButtonState(favoriteBtn, favoritesSet.has(favoriteKey));
@@ -185,6 +188,7 @@ App.videos = App.videos || {};
state.renderedVideoIds.add(v.id); state.renderedVideoIds.add(v.id);
}); });
App.videos.scheduleMasonryLayout();
App.videos.ensureViewportFilled(); App.videos.ensureViewportFilled();
}; };
@@ -229,6 +233,32 @@ App.videos = App.videos || {};
} }
}; };
let masonryRaf = null;
App.videos.scheduleMasonryLayout = function() {
if (masonryRaf) {
cancelAnimationFrame(masonryRaf);
}
masonryRaf = requestAnimationFrame(() => {
masonryRaf = null;
App.videos.applyMasonryLayout();
});
};
App.videos.applyMasonryLayout = function() {
const grid = document.getElementById('video-grid');
if (!grid) return;
const styles = window.getComputedStyle(grid);
if (styles.display !== 'grid') return;
const rowHeight = parseInt(styles.getPropertyValue('grid-auto-rows'), 10);
const rowGap = parseInt(styles.getPropertyValue('row-gap') || styles.getPropertyValue('gap'), 10) || 0;
if (!rowHeight) return;
Array.from(grid.children).forEach((item) => {
const itemHeight = item.getBoundingClientRect().height;
const span = Math.ceil((itemHeight + rowGap) / (rowHeight + rowGap));
item.style.gridRowEnd = `span ${span}`;
});
};
App.videos.updateLoadMoreState = function() { App.videos.updateLoadMoreState = function() {
const loadMoreBtn = document.getElementById('load-more-btn'); const loadMoreBtn = document.getElementById('load-more-btn');
if (!loadMoreBtn) return; if (!loadMoreBtn) return;