deploy: fix scroll jump when closing previous story
This commit is contained in:
@@ -301,11 +301,14 @@
|
|||||||
// Close ALL other story cards globally across all categories
|
// Close ALL other story cards globally across all categories
|
||||||
const allCards = document.querySelectorAll('.story-card');
|
const allCards = document.querySelectorAll('.story-card');
|
||||||
allCards.forEach(c => {
|
allCards.forEach(c => {
|
||||||
if (c !== card) {
|
if (c !== card && c.classList.contains('open')) {
|
||||||
c.classList.remove('open');
|
c.classList.remove('open');
|
||||||
const b = c.querySelector('.story-body');
|
const b = c.querySelector('.story-body');
|
||||||
if (b) {
|
if (b) {
|
||||||
|
b.style.transition = 'none';
|
||||||
b.style.maxHeight = '0px';
|
b.style.maxHeight = '0px';
|
||||||
|
b.offsetHeight; // Force reflow
|
||||||
|
b.style.transition = ''; // Restore transition for next open
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -318,7 +321,7 @@
|
|||||||
// Smoothly scroll the newly opened story card to the top of the viewport
|
// Smoothly scroll the newly opened story card to the top of the viewport
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
card.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||||
}, 100);
|
}, 50); // Small delay to allow reflow, works perfectly and instantly
|
||||||
} else {
|
} else {
|
||||||
card.classList.remove('open');
|
card.classList.remove('open');
|
||||||
if (body) {
|
if (body) {
|
||||||
|
|||||||
Reference in New Issue
Block a user