Version 1.0.3
A jQuery plugin that shows placeholder images for embedded YouTube or Vimeo videos, and only loads the video after clicking the placeholder. This alows for faster page loads as the video's, cookies, and other files of the video services are loaded when the video is actually started.
Jurgen Oldenburg ( @staxxnl / jold.nl / [email protected] )
Include jquery.jold.js-load-video.min.js
after calling jQuery in the footer. Alternatively, include in your plugins.js
file if using HTML5 Boilerplate.
$ npm install jquery.jold.js-load-video
<div class="video-container">
<div class="js-load-video" data-service="vimeo" data-placeholder="" data-embed="306834650">
<a href="#" class="btn btn-play" title="Play video">Play</a>
</div>
</div>
Data attribute | Description |
---|---|
data-service | Can be either YouTube or Vimeo. Other services are not supported. |
data-placeholder | You can provide your own placeholder (url). Leave this empty to retrieve the thumbnail from YouTube or Vimeo automatically. |
data-embed | The video key or ID from YouTube or Vimeo |
The plugin has three options you can set:
youtubeThumbSize: Set the YouTube placeholder thumbnail image size.
Default: 'maxresdefault'
vimeoThumbSize: Set Vimeo placeholder image image size. Read more:
Default: 'thumbnail_large'
placeholderClass: Css class of the placeholder image tag
Default: 'img-fluid'
$('.js-load-video').joldJsLoadVideo({
youtubeThumbSize: 'hqdefault',
vimeoThumbSize: 'thumbnail_large'
placeholderClass: 'img-fluid'
});
This example checks for all .js-load-video elements, places a placeholder and loads the video on click.
Tested with jQuery 1.12.1.
- FIX: Get image class from setting, not hardcoded
- Improve documentation and demonstration files
- Remove unused dependencies
- Only set automatic placeholder image if data-placeholder is empty
- Update outdated packages, removing all vulnerabilities
- Initial commit.