Skip to content

Commit a49d382

Browse files
fix programmatic scroll calc
1 parent 961f0c9 commit a49d382

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • src/player/types/ContentView

src/player/types/ContentView/type.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,17 +1564,25 @@ FrameTrail.defineType(
15641564
// Only scroll when the active set changes
15651565
if (!activeSetChanged) return;
15661566

1567-
// Compute midpoint of all active elements
1567+
// Compute scroll target from active elements
15681568
var firstEl = self.getContentViewElementFromContentItem(activeAnnotations[0]);
15691569
var lastEl = self.getContentViewElementFromContentItem(activeAnnotations[activeAnnotations.length - 1]);
15701570
if (!firstEl || !lastEl) return;
15711571

15721572
self._isProgrammaticScroll = true;
15731573
if (slideAxis == 'x') {
1574-
var groupLeft = firstEl.offsetLeft;
1575-
var groupRight = lastEl.offsetLeft + lastEl.offsetWidth;
1576-
var groupCenter = (groupLeft + groupRight) / 2;
1577-
var scrollTarget = groupCenter - scrollContainer.clientWidth / 2;
1574+
var containerWidth = FrameTrail.getState('viewSize')[0];
1575+
if (containerWidth < 768 || activeAnnotations.length === 1) {
1576+
// Small container: center only the first active element
1577+
var elCenter = firstEl.offsetLeft + firstEl.offsetWidth / 2;
1578+
var scrollTarget = elCenter - scrollContainer.clientWidth / 2;
1579+
} else {
1580+
// Large container: center the midpoint of all active elements
1581+
var groupLeft = firstEl.offsetLeft;
1582+
var groupRight = lastEl.offsetLeft + lastEl.offsetWidth;
1583+
var groupCenter = (groupLeft + groupRight) / 2;
1584+
var scrollTarget = groupCenter - scrollContainer.clientWidth / 2;
1585+
}
15781586
scrollContainer.scrollTo({ left: Math.max(0, scrollTarget), behavior: 'smooth' });
15791587
} else {
15801588
var groupTop = firstEl.offsetTop;

0 commit comments

Comments
 (0)