The change to the CSS class and the properties cause a recalculation that could sometimes interfere with the page scrolling.
Forcing the scrolling into the next iteration of the event loop solves this issue by separating both actions. Since the scrolling does depend on the actions in the lines above it, this is reasonably safe to do.
}
if (_scrollTop) {
- document[_scrollOffsetFrom].scrollTop = ~~_scrollTop;
+ // Slightly delay this to prevent conflicts caused by a CSS recalculation.
+ window.setTimeout(() => {
+ document[_scrollOffsetFrom].scrollTop = ~~_scrollTop;
+ }, 1);
}
}
}
pageContainer.style.removeProperty("margin-top");
}
if (_scrollTop) {
- document[_scrollOffsetFrom].scrollTop = ~~_scrollTop;
+ // Slightly delay this to prevent conflicts caused by a CSS recalculation.
+ window.setTimeout(() => {
+ document[_scrollOffsetFrom].scrollTop = ~~_scrollTop;
+ }, 1);
}
}
}