@maeertin/medialoaded
v1.2.1
Published
A simple utility for checking whether images and/or videos have been loaded.
Downloads
659
Maintainers
Readme
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.
# 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)
})