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

backgrounded

v1.1.2

Published

Backgrounded is a plugin that helps you with HTML5 background videos, specifically background videos with large file sizes. Say you have a business requirement to add a very large background video to your website. You don't want to have the video bufferin

Downloads

4

Readme

Backgrounded

Backgrounded is a plugin that helps you with HTML5 background videos, specifically background videos with large file sizes. Say you have a business requirement to add a very large background video to your website. You don't want to have the video buffering and stuttering and you don't want to add a super long preloader while everything comes down the tubes. With Backgrounded you can have two versions of a video, one that is a smaller file size, and then the beefy full res high quality video. Backgrounded will load the low quality video first, and then swap in the high quality one when it is ready to go. Backgrounded will also take care of scaling the video to fit the height and width of its container div (like background: cover in css).

Getting started

Install

npm install backgrounded

Include

import Backgrounded from 'backgrounded';

or

const Backgrounded = require('backgrounded');

Basic Use

<div id="container"></div>

<script>
    let backgroundVideo = Backgrounded('#container', [
        [
            { src: '/low-quality.webm', type: 'video/webm' },
            { src: '/low-quality.mp4',  type: 'video/mp4'  },
            { src: '/low-quality.ogv',  type: 'video/ogg'  }
        ],
        [
            { src: '/high-quality.webm', type: 'video/webm' },
            { src: '/high-quality.mp4',  type: 'video/mp4'  },
            { src: '/high-quality.ogv',  type: 'video/ogg'  }
        ]
    ]);
</script>

API

backgrounded = Backgrounded(container, videos)

Returns an instance of Backgrounded.

  • container A query selector or DOM node that the video will fill upon load.
  • videos An array of video elements or arrays that represent the source files for the video. The videos will load in priority of their index in the videos array, with the last element being the desired final full quality video.

.play()

Will play the video background.

.pause()

Will pause the video background.

Properties

.activeVideo

Read only getter that returns the active video element.

.videoElements

Read only getter that returns the video elements.

.canvas

Read only getter that returns the canvas element that the video plays in.

.container

Read only getter that returns the container element.

Events

Backgrounded will emit some events that can be subscribed to with .on(eventName, listener) or .once(eventName, listener) and detached with .off(eventName, listener). Currently Backgrounded extends Smelly Event Emitter so you can visit their documentation if you need more power, but this could change in the future. However if I change the event emitter, .on, .once, and .off should not change.

.on('canplaythrough', (videoElement, index) => {})

The canplaythrough event's listener will be called with the videoElement that canplaythrough as the first argument, and the index of that element in the initial videos array as it's second argument.

.on('setactivevideo', videoElement => {})

The setactivevideo listener will be called with the video element that has been set as the current active video.

.on('resize', () => {})

The resize listener will be called when the video has been resized to fill it's container.

.on('playing', videoElement => {})

The playing listener will be called with the active video element when the video is played.

.on('paused', videoElement => {})

The paused listener will be called with the active video element when the video is paused.