This is a jQuery plugin to lazy load Youtube and Vimeo videos. On the initial load, the div
will be appended by a preview img
of the video. On click of the image, the preview img
will be replaced by the autoplaying iframe
Youtube or Vimeo video.
To read more information on the plugin and access a demo, view the intro post on newmediacampaigns.com.
- Demo of v1.0.1
- View the demo. (older version)
For Youtube:
<div class="lazyYT" data-youtube-id="_oEA18Y8gM0" data-ratio="16:9">loading...</div>
For Vimeo:
<div class="lazyYT" data-vimeo-id="_oEA18Y8gM0" data-ratio="16:9">loading...</div>
- Include the lazyYT JS and CSS files.
- Add a
div
where you want the video to be located. Add the id of the Youtube/Vimeo video to the data attributeyoutube-id
. - Either add the video width and height to
data-width
anddata-height
, or add an ascpent ratio like16:9
todata-ratio
, none are required. - Youtube only: Any optional parameters you wanted passed to the iframe url should be added to
data-parameters
. - Get it started with
$('.lazyYT').lazyYT();
(CC) Creative Commons