vidscroll0.3.3

Custom loaders

Replace, restyle or remove the loading overlay and the re-encode badge.

While a video loads, ScrollVideo shows a translucent overlay with a progress bar. During an in-browser re-encode, the overlay gives way to a small badge in the corner, because the original video can already be scrolled. Both can be replaced, restyled or removed.

The loading states

PhaseWhenCovers the video?
downloadThe file is being fetchedYes
preparingA quick pass over the timeline before scrubbing startsYes
optimizeThe browser is re-encoding the videoNo: corner badge, the original is already scrollable
errorThe video can’t be loaded or playedYes, with the error message

With optimize={{ wait: true }}, the optimize phase covers the video too.

Your own loader

Pass a function to loader. It receives the state and the built-in loader for that state, so you can wrap or replace it:

Hero.tsx
<ScrollVideo
  src="/videos/hero.mp4"
  loader={(state, builtIn) =>
    state.background ? builtIn : <p className="loading">Loading {Math.round(state.progress * 100)}%</p>
  }
/>

The state has phase, progress (0 to 1), background (true for the corner badge) and error (in the error phase). Returning null shows nothing for that state.

Other forms:

loaderResult
not setThe built-in overlay and badge
a React elementShown while the video is covered; no badge during a re-encode
a functionCalled for every state, including the badge
falseNothing at all

Errors always show their message unless you handle the error phase in a function. onError receives the same error if you’d rather show it elsewhere.

Restyling the built-in one

The built-in loader is plain markup with attributes you can target from CSS:

styles.css
[data-vidscroll-loader] {
  background: rgb(0 0 0 / 0.8);
}

[data-vidscroll-loader][data-background] {
  inset: 16px 16px auto auto;
}

[data-vidscroll-loader][data-phase="download"] {
  font-family: Georgia, serif;
}

The second rule moves the badge to the top-right corner. To keep the overlay but hide the badge, set display: none on [data-vidscroll-loader][data-background].

What’s behind the loader

By default the video’s first frame shows behind the loading overlay. poster shows an image instead, or nothing:

Hero.tsx
<ScrollVideo src="/videos/hero.mp4" poster="/images/hero-poster.jpg" />