npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nzz/et-video-scroller

v0.1.1

Published

A component for scroll-based (or other externally controlled) playback.

Downloads

12

Readme

ScrollyVideo.js

This video scroller based on video scroller of dkaoster. This is a fork of the original project, with some modifications and improvements.

🚀 Web

Add html container to your page:

<div id="scrolly-video"></div>

Require javascript in your page and create the object (before </body>):

<script src="https://cdn.jsdelivr.net/npm/scrolly-video@latest/dist/scrolly-video.js"></script>
<script type="text/javascript">
  new ScrollyVideo({
    scrollyVideoContainer: 'scrolly-video',
    src: 'https://scrollyvideo.js.org/goldengate.mp4',
  });
</script>

You can replace @latest with specific version, example @0.0.2.

🔵 React

Install npm module with npm install scrolly-video --save: Import component in your application:

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:

<ScrollyVideo src="https://scrollyvideo.js.org/goldengate.mp4" />

🟠 Svelte

Install npm module with npm install scrolly-video --save: Import component in your application:

import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.svelte';

Add the ScrollyVideo component to your application:

<ScrollyVideo src="https://scrollyvideo.js.org/goldengate.mp4" />

🟢 Vue

Install npm module with npm install scrolly-video --save: Import module in your src/App.vue and config:

import ScrollyVideo from 'scrolly-video/dist/ScrollyVideo.vue';

Add html code to your html component:

<ScrollyVideo src="https://scrollyvideo.js.org/goldengate.mp4" />

🧰 Options / Attributes

| 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 | | contain | Forces the video to cover in it's container | cover, contain | cover | | sticky | Whether the video should have position: sticky | Boolean | true | | 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 setVideoPercentage 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 |

Additional callbacks

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 })

Technical Details and Cross Browser Differences

To make this library perform optimally in all browsers, three different approaches are taken to animating the video.

Method 1: WebCodecs and Canvas

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:

Method 2: HTML5 Video and playbackRate

This method simply embeds the video with an HTML <video> tag, and it plays the video when the video needs to be animated. To adjust to the scroll speed, this method modulates the playbackRate attribute on the video in order to dynamically mimic a faster or slower scroll speed. This method is extremely smooth when the scroll direction is moving the video forward, but unfortunately does not work in reverse because playbackRate cannot be a negative value.

Thus, if the video needs to be animated backwards, this library falls back to method 3.

Method 3: HTML5 Video and currentTime

This method is the way that scrollytelling videos have traditionally been done, using an HTML <video> tag and skipping directly to frames using currentTime. However, this method requires the video to be encoded at keyframe = 1, which causes the video to be a lot larger or the quality to drop. Unfortunately, this is the only option for scenarios where methods 1 and 2 are not supported, or on mobile safari browsers where somehow this method performs better than method 2. Thus, to achieve maximum performance under all circumstances, it is still recommended to encode videos with keyframe = 1, if possible.

Known Issues

  • 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.