In my case this was caused by images using lazy loading, thus only loading when in view.
This fixed it for me, add this to the bottom of the script.
let resizeTimeout;
function refreshLenis() {
clearTimeout(resizeTimeout); // Cancel previous resize calls
resizeTimeout = setTimeout(() => {
requestAnimationFrame(() => {
lenis.resize(); // Recalculate dimensions inside requestAnimationFrame for smoother transitions
});
}, 300); // Adjust delay as needed
}
// Refresh Lenis when the page fully loads
window.addEventListener("load", refreshLenis);
// Also refresh Lenis when lazy-loaded images finish loading
document.querySelectorAll("img[loading='lazy']").forEach((img) => {
img.addEventListener("load", refreshLenis);
});