@maeertin/medialoaded

1.2.1 • Public • Published

mediaLoaded

A simple utility for checking whether images, videos and/or video posters have been loaded. Inspired by imagesLoaded.

Sidenote: On touch devices, all videos that don't autoplay will be ignored as video events won't trigger until user interaction.

Install with npm or Yarn:

# via npm
npm install @maeertin/medialoaded

# or Yarn
yarn add @maeertin/medialoaded

Usage:

import mediaLoaded from '@maeertin/medialoaded'

// Single node as target argument
const element = document.querySelector('#container')
mediaLoaded(element, instance => {
  console.log('All media loaded', instance)
})

// nodeList as target argument
const elements = document.querySelectorAll('.post')
mediaLoaded(elements, instance => {
  console.log('All media loaded', instance)
})

// String selector as target argument
mediaLoaded('.post', instance => {
  console.log('All media loaded', instance)
})

Package Sidebar

Install

npm i @maeertin/medialoaded

Weekly Downloads

183

Version

1.2.1

License

MIT

Unpacked Size

10.3 kB

Total Files

10

Last publish

Collaborators

  • maeertin