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

wtc-autoplay-video

v2.0.4

Published

Autoplaying video class

Downloads

131

Readme

wtc-autoplay-video 2.0.4

Autoplaying video class

src/wtc-autoplay-video.js

new AutoplayVideo()

The AutoplayVideo class expects an element (as all wtc-element-controllers do) and can take an optional options argument

Install

$ npm install wtc-autoplay-video

Usage

Import it in your project.

import AutoplayVideo from 'wtc-autoplay-video';

Add the markup.

<div class="autoplay-video">
  <video
    class="autoplay-video__video"
    autoplay
    playsinline
    muted
    loop
  >
    <source
      src="video.mp4"
      type="video/mp4"
    />
  </video>
  <!-- REQUIRED -->
  <img
    class="autoplay-video__fallback"
    src="fallback.png"
    alt="Fallback"
  />
  <!-- OPTIONAL -->
  <img
    class="autoplay-video__preloader"
    src="preloader.png"
    alt="Preloader"
  />
</div>

1. Using ExecuteControllers

If you are using [wtc-controller-element] just data-controller="AutoplayVideo" to your markup.

<div data-controller="AutoplayVideo" class="autoplay-video">
...

You can also instanciate explicitly:

ExecuteControllers.instanciate(document.getElementById('autoplay-video'), AutoplayVideo);

2. Default JS

With the default js version, you have the option to pass the options as an object, or use data-attributes, they both work.

let gallery = new AutoplayVideo(document.getElementById('autoplay-video'), {
  vpOn: 30
});

3. ES5 version

There's also an ES5 version to be used in browser anywhere. It's also really simple. Add you markup, then add the script:

<script src="dist/wtc-autoplay-video.es5.js"></script>

And for last, instanciate the videos:

<script>
  var videos = document.querySelectorAll('.autoplay-video');
  for (var i = 0; i < videos.length; i++) {
    new WTCAutoplayVideo.default(videos[i], { vpOn: 0 });
  }
</script>

Options

The options object is comprised of the following:

| Name | HTML Attribute | Type | Description | Default | | ---- | -------------- | ---- | ----------- | ------- | | vpOn | data-vp-on | Number | The point at which the video should start playing after havign scrolled on the screen. | 0 | | startAt | data-autoplay-video--start-at | Number | When the video starts playing again, start at this point, in seconds. | null | | loopFrom | data-autoplay-video--loop-from | Number | When the video reaches this part, loop. If this isn't provided, the end of the video will be the loop point. | null | | loopTo | data-autoplay-video--loop-to | Number | When the video loops, this is the point that it will start the loop from. | null |

Class Documentation

Returns
  • A new instance of the AutoplayVideo class

constructor(element, options)

Creates an instance of AutoplayVideo.

Options object is comprised of the following:

| Name | Type | Description | Default | | ---- | ---- | ----------- | ------- | | vpOn | Number | The point at which the video should start playing after havign scrolled on the screen. | 0 | | startAt | Number | When the video starts playing again, start at this point, in seconds. | null | | loopFrom | Number | When the video reaches this part, loop. If this isn't provided, the end of the video will be the loop point. | null | | loopTo | Number | When the video loops, this is the point that it will start the loop from. | null |

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | element | DOMElement | |   | | options | Object | |   |

Returns
  • Void

init()

This method initialises the loaded video, sets up our ratios and attaches the relevant event listeners.

Returns
  • Void

videoResize()

Resize the video to the size of its parent. This is normally called as a part of the window resize handler but can also be called programatically.

Returns
  • Void

onPlay()

Responds to the videos playing method. This is responsible for setting the various state properties and starting up the run loop, if we need internal video looping.

Returns
  • Void

onFrozen()

If for some reason the video fails to play, this method will be called. This adds an is-frozen class name to the element and sets videoPlaying property to false.

Returns
  • Void

onPause()

When the video is paused this method is called. This adds the is-paused class name to the element, sets the hasStarted and videoPlaying properties to false.

Returns
  • Void

onEnded()

This responds to the videos ended event and is responsible for looping the video only when a both a loopTo property is provided and a loopFrom property is not.

Returns
  • Void

onLoopCheck(delta)

This method is a part of the run loop for the video. It will only run when the video is playing (on screen) and when both the loopTo and loopFrom properties are provided

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | delta | Number | |   |

Returns
  • Void

pauseVideo()

This method pauses the video and is intended to be called programatically.

Returns
  • Void

playVideo()

This method plays the video and is intended to be called programatically.

Returns
  • Void

viewportAnimationCallback(topPercent)

This method overrides the parent class' viewportAnimationCallback method and provides play/pause functionality based on the viewport position. Basically this stops the video from playing unless it's on-screen.

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | topPercent | any | |   |

Returns
  • Void

video()

(getter/setter) The video element itself

Returns
  • HTMLElement

fallback()

(getter/setter) The fallback element

Returns
  • HTMLElement

hasStarted()

(getter/setter) Whether the video has started playing

Returns
  • boolean

initiated()

(getter/setter) Whether the instance has been initiated

Returns
  • boolean

loopPeriod()

(getter/setter) Whether the instance is operating over a loop period

Returns
  • boolean

videoPlaying()

(getter/setter) Whether the video has started playing. This is specifically for the determination of the run loop.

Returns
  • boolean

ratio()

(getter/setter) The video's aspect ratio.

Returns
  • number

startAt()

(getter) The place in the video to start at, in seconds. Set from the passed options.

Returns
  • number

loopFrom()

(getter) The place in the video to loop from, in second. This should be greater than loopTo (not sure what happens if not ^_^ ). Set from the passed options.

Returns
  • number

loopTo()

(getter) The place in the video to loop, in seconds. Set from the passed options

Returns
  • number

Documentation generated with doxdox.