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

vidbg.js

v2.1.0

Published

A minimal vanilla JavaScript video background plugin.

Downloads

53

Readme

vidbg.js

A minimal vanilla JavaScript video background plugin.

Compatibility

  • All modern web browsers
  • IE 11+
  • All mobile web browsers that support autoplaying HTML5 <video>

Working With Wordpress

If you plan on using vidbg.js with WordPress, make your life a little bit easier and download the plugin I made on the Wordpress Repo.

Usage

Install

npm install vidbg.js

Instructions

In the browser:

<!-- <head> -->
<link href="dist/vidbg.css" rel="stylesheet" type="text/css" />

<!-- End of <body> -->
<script src="dist/vidbg.js"></script>

Or if you are working with modules:

import vidbg from "vidbg.js";

Initializing the Script

The script accepts three arguments.

var instance = new vidbg(selector, options, attributes);

The selector argument is any JavaScript selector, the options are for configuring vidbg.js, and the attributes argument modifies the actual <video> element.

var instance = new vidbg(
  ".vidbg-box",
  {
    mp4: "http://example.com/video.mp4", // URL or relative path to MP4 video
    webm: "path/to/video.webm", // URL or relative path to webm video
    poster: "path/to/fallback.jpg", // URL or relative path to fallback image
    overlay: false, // Boolean to display the overlay or not
    overlayColor: "#000", // The overlay color as a HEX
    overlayAlpha: 0.3, // The overlay alpha. Think of this as the last integer in RGBA()
  },
  {
    // Attributes
  }
);

Note: Supplying both .mp4 and .webm will increase browser compatibility.

Options

const defaultOptions = {
  mp4: null,
  webm: null,
  poster: null,
  overlay: false,
  overlayColor: "#000",
  overlayAlpha: 0.3,
};

Attributes

const defaultAttributes = {
  autoplay: true,
  controls: false,
  loop: true,
  muted: true,
  playsInline: true,
};

Overlay

Setting the overlay option to true will add an RGBA background over your video. This is helpful when you want to display text or meaningful content over the video background to increase legibility.

Fallback Image Flashing

You may experience the fallback image flash on page load. This is because the fallback image is added through JavaScript. As a result of this, it will load after CSS styles are rendered.

If you'd like to combat this, you can preset the fallback image through CSS. For example, if your selector is .video-box you could do something like:

.video-box .vidbg-container {
  background-image: url(/assets/link-to-fallback.png);
}

Methods

Below are the methods that are available:

// First, create the vidbg.js instance.
var instance = new vidbg(".vidbg-box", {
  mp4: "http://example.com/video.mp4",
  webm: "path/to/video.webm",
  poster: "path/to/fallback.jpg",
});

// Manually resize the video background
instance.resize();

// Manually play the video
instance.playVideo();

// Manually pause the video
instance.pauseVideo();

// Get the video playing state
instance.isVideoPlaying();

// Remove the <video> element
instance.removeVideo();

// Completely remove the video background
instance.destroy();

Media

Video and fallback image provided by Christophe Tauziet at https://vimeo.com/user27974867

License

vidbg.js is licensed under The MIT License. You can view it here.