A component for scroll-based (or other externally controlled) playback.
npm install scrolly-videoA component for scroll-based (or other externally controlled) playback. See /demos for full example usages.
Add html container to your page:
``html`
Require javascript in your page and create the object (before
):`html`
You can replace @latest with specific version, example @0.0.2.
Install npm module with npm install scrolly-video --save:
Import component in your application:
`javascript`
import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.cjs.jsx';
or
import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.esm.jsx';
Add the component where you need it:
`html`
Install npm module with npm install scrolly-video --save:
Import component in your application:
`javascript`
import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.svelte';
Add the ScrollyVideo component to your application:
`html`
Install npm module with npm install scrolly-video --save:src/App.vue
Import module in your and config:
`javascript`
import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.vue';
Add html code to your html component:
`html`
Install npm module with npm install scrolly-video --save:
Import component in your frontmatter:
`javascript`
import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.astro';
`html`
| Parameter | Description | Values | Default |
|:----------------------|:---------------------------------------------------------------------------------------------------------|:-----------------|:--------|
| src | The URL of the video (required) | URL | |
| scrollyVideoContainer | The DOM element of the container, only used for plain js | String / Element | |
| transitionSpeed | Sets the maximum playbackRate for this video | Number | 8 |
| frameThreshold | When to stop the video animation, in seconds | Number | 0.1 |
| cover | Forces the video to cover in it's container | Boolean | true |
| sticky | Whether the video should have position: sticky | Boolean | true |setVideoPercentage
| full | Whether the video should take up the entire viewport | Boolean | true |
| trackScroll | Whether this object should automatically respond to scroll | Boolean | true |
| lockScroll | Whether it ignores human scroll while it runs with enabled trackScroll | Boolean | true |
| useWebCodecs | Whether the library should use the webcodecs method, see below | Boolean | true |
| videoPercentage | Manually specify the position of the video between 0..1, only used for react, vue, and svelte components | Number | |
| onReady | The callback when it's ready to scroll | VoidFunction | |
| onChange | The callback for video percentage change | VoidFunction | |
| debug | Whether to log debug information | Boolean | false |
setVideoPercentage
Description: A way to set currentTime manually. Pass a progress in between of 0 and 1 that specifies the percentage position of the video. If trackScroll enabled - it performs scroll automatically.
Signature: (percentage: number, options: { transitionSpeed: number, (progress: number) => number }) => void
Example: scrollyVideo.setVideoPercentage(0.5, { transitionSpeed: 12, easing: d3.easeLinear })
To make this library perform optimally in all browsers, three different approaches are taken to animating the video.
Using the new WebCodecs API we are able to get all frames in the video and have them ready to draw to a canvas. This method is the most performant, but has two drawbacks: first, depending on the device and the size of the video, using the WebCodecs API will take some time to process all the frames, so the animation will not be available immediately upon page load. Secondly, the WebCoedecs API is currently only available on Chrome, and the WebCodecs polyfill does not work for this application.
If WebCodecs is not supported by the browser or has not finished processing all frames, it falls back to method 2:
This method simply embeds the video with an HTML
Thus, if the video needs to be animated backwards, this library falls back to method 3.
This method is the way that scrollytelling videos have traditionally been done, using an HTML
- On iOS, ScrollyVideo will not work if battery saver mode is on. Unfortunately, there is no workaround for this due to the way that iOS handles videos and battery saving functions.
---
Created by: Daniel Kao