+
@@ -292,6 +280,11 @@
.scroller-video-container {
width: 100%;
+ // Needs to be >= 100lvh to allow child element to scroll
+ // 200lvh provides smoother scrolling experience -->
+ &.embedded {
+ height: 200lvh;
+ }
&:not(.embedded) {
min-height: 100lvh;
}
diff --git a/src/components/ScrollerVideo/demo/Embedded.svelte b/src/components/ScrollerVideo/demo/Embedded.svelte
index d762b740..d8cff44f 100644
--- a/src/components/ScrollerVideo/demo/Embedded.svelte
+++ b/src/components/ScrollerVideo/demo/Embedded.svelte
@@ -3,6 +3,7 @@
import ScrollerVideoForeground from '../ScrollerVideoForeground.svelte';
import Goldengate from '../videos/goldengate.mp4';
import BodyText from '../../BodyText/BodyText.svelte';
+ import Block from '../../Block/Block.svelte';
import type { ContainerWidth } from '../../@types/global';
@@ -46,22 +47,24 @@
const dummyText =
'Reprehenderit hamburger pork bresaola, dolore chuck sirloin landjaeger ham hock tempor meatball alcatra nostrud pork belly. Culpa pork belly doner ea jowl, elit deserunt leberkas cow shoulder ham hock dolore.';
const scrollerVideoBlock = content.blocks[0];
+
+ let embedded = $state(true);
+
+
+
+
+
+
+
+
+
diff --git a/src/components/ScrollerVideo/ts/ScrollerVideo.ts b/src/components/ScrollerVideo/ts/ScrollerVideo.ts
index b1457d00..d8db3863 100644
--- a/src/components/ScrollerVideo/ts/ScrollerVideo.ts
+++ b/src/components/ScrollerVideo/ts/ScrollerVideo.ts
@@ -4,7 +4,7 @@ import { debounce, isScrollPositionAtTarget, map, constrain } from './utils';
import { createComponentState, type ScrollerVideoState } from './state.svelte';
interface ScrollerVideoArgs {
- src?: string;
+ src: string;
scrollerVideoContainer: HTMLElement | string;
objectFit?: string;
sticky?: boolean;
@@ -192,7 +192,7 @@ class ScrollerVideo {
* @param {ScrollerVideoArgs} args - The arguments for initialization.
*/
constructor({
- src = 'https://scrollyvideo.js.org/goldengate.mp4',
+ src,
scrollerVideoContainer,
objectFit = 'cover',
sticky = true,
@@ -202,8 +202,8 @@ class ScrollerVideo {
transitionSpeed = 8,
frameThreshold = 0.1,
useWebCodecs = true,
- onReady = () => {},
- onChange = (_percentage?: number) => {},
+ onReady = () => { },
+ onChange = (_percentage?: number) => { },
debug = false,
autoplay = false,
}: ScrollerVideoArgs) {
@@ -240,24 +240,8 @@ class ScrollerVideo {
this.totalTime = 0; // The total time of the video, used for calculating percentage
this.transitioningRaf = null;
this.componentState = createComponentState();
-
this.componentState.willAutoPlay = autoplay;
- // Make sure that we have a DOM
- if (typeof document !== 'object') {
- console.error('ScrollerVideo must be initiated in a DOM context');
- return;
- }
-
- // Make sure the basic arguments are set for scrollervideo
- if (!scrollerVideoContainer) {
- console.error('scrollerVideoContainer must be a valid DOM object');
- return;
- }
- if (!src) {
- console.error('Must provide valid video src to ScrollerVideo');
- return;
- }
// Save the container. If the container is a string we get the element
@@ -741,7 +725,7 @@ class ScrollerVideo {
const hasPassedThreshold =
isForwardTransition ?
this.currentTime >= this.targetTime
- : this.currentTime <= this.targetTime;
+ : this.currentTime <= this.targetTime;
if (this.componentState.isAutoPlaying) {
this.componentState.autoplayProgress = parseFloat(
@@ -780,7 +764,7 @@ class ScrollerVideo {
isForwardTransition ?
startCurrentTime +
easedProgress * Math.abs(distance) * transitionSpeed
- : startCurrentTime -
+ : startCurrentTime -
easedProgress * Math.abs(distance) * transitionSpeed;
if (this.canvas) {
@@ -869,7 +853,7 @@ class ScrollerVideo {
const targetDuration =
this.frames?.length && this.frameRate ?
this.frames.length / this.frameRate
- : this.video?.duration || 0;
+ : this.video?.duration || 0;
// The time we want to transition to
this.targetTime = Math.max(Math.min(percentage, 1), 0) * targetDuration;