Hi,
I want my site to show a loading overlay only when someone first visits the homepage.
On their first visit:
- Show the loading overlay
- Auto-scroll to the hero section
- Lock scrolling during loading so no one can manually scroll past it
On any subsequent refresh or revisit:
- The loading overlay should not show
- The page should load directly at the hero section, with no scroll lock
What I need help with:
- How do I set up my code so that the loading overlay appears only on the first visit?
- How do I make sure refreshing the page doesn’t show the overlay?
- How do I prevent the scroll lock from remaining active after the first visit?
I’m using:
- sessionStorage to track if it’s the first visit
- Custom code for showing/hiding the overlay and locking scroll
My velo code on home right now
import wixWindowFrontend from ‘wix-window-frontend’;
import wixLocationFrontend from ‘wix-location-frontend’;
import { session } from ‘wix-storage-frontend’;
$w.onReady(async () => {
console.log(‘onReady fired’);
const alreadyPlayed = session.getItem(‘introPlayed’);
console.log(‘alreadyPlayed value:’, alreadyPlayed);
const currentUrl = wixLocationFrontend.url;
const urlParts = currentUrl.split(‘#’);
const anchorId = urlParts.length > 1 ? urlParts[1] : null;
if (alreadyPlayed === ‘true’) {
console.log(‘Taking SKIP branch’);
try {
await $w(‘#loading-page’).collapse();
console.log(‘collapse() succeeded’);
} catch (e) {
console.log(‘collapse() FAILED:’, e.message);
}
if (anchorId) {
setTimeout(() => { $w(‘#’ + anchorId).scrollTo(); }, 50);
}
} else {
console.log(‘Taking PLAY INTRO branch’);
session.setItem(‘introPlayed’, ‘true’);
try {
await $w(‘#loading-page’).expand();
console.log(‘expand() succeeded’);
} catch (e) {
console.log(‘expand() FAILED:’, e.message);
}
setTimeout(async () => {
console.log(‘3100ms timer fired’);
if (wixLocationFrontend.url.includes(‘#’)) {
await $w(‘#loading-page’).collapse();
return;
}
await $w(‘#section1’).scrollTo();
await $w(‘#loading-page’).collapse();
wixWindowFrontend.scrollTo(0, 0, { scrollAnimation: false });
console.log(‘Intro sequence complete’);
}, 3100);
}
$w(‘#colour-trigger-line’).onViewportLeave(() => {
$w(‘#feral-logo-white, #menu-white’).hide(“fade”);
$w(‘#feral-logo-red, #menu-red’).show(“fade”);
});
$w(‘#colour-trigger-line’).onViewportEnter(() => {
$w(‘#feral-logo-white, #menu-white’).show(“fade”);
$w(‘#feral-logo-red, #menu-red’).hide(“fade”);
});
});
My lock scroll custom header code in settings for home right now
Thanks in advance!