LazyLoad Embed YouTube Player - simple and lightweight plugin - pure JavaScript

Overview

Youtube LazyLoad

LazyLoad Embed Youtube Player - simple and lightweight plugin - pure JavaScript


Status

GitHub Version License

Github Star Github Fork

CSS gzip size JS gzip size


View Preview



Table of contents


Quick Start

Several options are available:

  • Download the latest release.
  • Clone the repo: git clone https://github.com/the-muda-organization/youtube-lazyload.git
  • Install with Composer: composer require the-muda-organization/youtube-lazyload

What's included

Within the download you'll find the following directories and files, logically grouping common assets and providing both compiled and minified variations. You'll see something like this:

There are no dependencies. No jQuery or other plugins required. See below for Installation Guide and How to Use

yt-lazyload/
 │
 └─ dist/
    │
    ├── css/
    │   ├── yt-lazyload.css
    │   └── yt-lazyload.min.css
    │
    └── js/
        ├── yt-lazyload.js
        └── yt-lazyload.min.js

Bugs and feature requests

Have a bug or a feature request? Before opening a new issue search for existing and closed issues. If your problem or idea is not addressed yet, open a new issue.


Installation

  1. Download and copy files to your project
  2. Open yt-lazyload.js
  3. Change settings:
    • settings_thumb_base_url to custom URL where your thumbnails are located.
  4. Minify JavaScript and place it in yt-lazyload.min.js.
  5. Add CSS and JavaScript to your project:
    <link href="https://example.com/yt-lazyload/4.x.x/css/yt-lazyload.min.css" rel="stylesheet">
    <script src="https://example.com/yt-lazyload/4.x.x/js/yt-lazyload.min.js"></script>

NOTE: Because of small file sizes I recommend adding CSS & JS inline!

    <style>...</style>
    <script>...</script>

How to Use

  1. Get Youtube ID of your movie, example: d4AmYBhGBfM
  2. Add the folowing code to embed a video:
<div class="yt-lazyload" data-id="d4AmYBhGBfM" data-thumb="" data-logo="3"></div>
  1. Name your thumbnail using Youtube ID d4AmYBhGBfM.jpg - to use other file types change settings in JavaScript
  2. Place your thumbnail in a folder set in JavaScript

Features

Attribute Explanation
class="yt-lazyload" Main container.

You can add additional style like border, box-shadow etc. or Bootstrap classes like img-thumbnail, shadow etc.
data-id="d4AmYBhGBfM" Youtube video ID
data-thumb="" If you need to add more thumbnails you can choose which one is displayed. It is usefull for quality specific thumbs (SD, 720p, 1080p) or in case of multiple thumbs random one can be selected.

Name your files d4AmYBhGBfM.jpg and add custom suffix.

For 3 thumbnails make d4AmYBhGBfM--1.jpg, d4AmYBhGBfM--2.jpg and d4AmYBhGBfM--3.jpg.

To show thumbnail 2 use data-thumb="--2" and so on.

You can randomize numbers using <?php echo mt_rand(1,3);?>.

Leave empty if you have only 1 thumbnail.
data-logo="3" Youtube logo color. You can customize it in CSS.

0 = none - logo will not be added by JavaScript,
1 = black,
2 = color-black,
3 = white,
4 = color-white (v4.0.0+).

CSS Classes

CSS class Explanation
.yt-lazyload main container
.yt-lazyload::before pseudo-element used to maintain container ratio and set background-color
.yt-lazyload-wrap container and its content added via javascript
.yt-lazyload-content container for play button, logo and thumbnail as background-image
.yt-lazyload-playbtn play button (black)
.yt-lazyload-playbtn:hover play button on hover (red)
.yt-lazyload-logo Youtube logo
.yt-lazyload-logo:hover Youtube logo on hover
.yt-lazyload[data-logo="X"] .yt-lazyload-logo Youtube logo color based on data attribute
.yt-lazyload iframe Youtube embeded iframe after click

FAQ

  • Can I use Youtube domain to get thumbnails?
    • I am not sure if it will work in all cases, but you can try. You need to adjust JavaScript.
    • Change settings_thumb_base_url = 'https://img.youtube.com/vi/';
    • Change this_content.style.setProperty('--yt-lazyload-img','url("' + settings_thumb_base_url + this_data_id + '/maxresdefault.jpg")');
  • Can I use Youtube lazyload with other frameworks like Bootstrap?
    • Yes you can! There should be no conflict with other frameworks.
  • Can I embed video players other than Youtube?
  • Does it work on mobile devices?

Versioning

Youtube LazyLoad will be maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format: <major>.<minor>.<patch>


Changelog

For last releases see detailed CHANGELOG.


Team


Code of conduct

We will behave ourselves if you behave yourselves. For more details see our CODE_OF_CONDUCT.md.


Copyright and license

Code and documentation copyright 2017-2020 The MUDA Organization.

Code released under the MIT License.


You might also like...

Prettier embeds for your YouTubes - with nice options like high-res preview images, advanced customization of embed options, and optional FitVids support.

Prettier embeds for your YouTubes - with nice options like high-res preview images, advanced customization of embed options, and optional FitVids support.

PrettyEmbed.js Prettier embeds for your YouTubes - with nice options like high-res preview images, advanced customization of embed options, and option

Sep 28, 2022

Cloudflare Workers Discord embed & keep URL example scripts.

Using Cloudflare Workers for Discord embed support Requirements: Your own image host, on a domain that you control via Cloudflare. Limitations: 100,00

Dec 27, 2022

Djs-paginate - Simpler discord.js v13 embed pagination tool

djs-paginate Simpler discord.js v13 embed pagination tool inspired by discordjs-button-pagination. Installation npm install @eugabrielsilva/djs-pagina

Jan 4, 2022

An open source Javascript framework for detecting the Adobe Flash Player plugin and embedding Flash (swf) files.

— IMPORTANT UPDATE —¶ ↑ SWFObject is no longer in active development. Flash Player is on the decline, and the authors of SWFObject have moved on to ot

Nov 27, 2022

Lightweight customizable placeholders for third party content of your website (e.g. Youtube Videos) compatible with the Usercentrics CMP.

Usercentrics Widgets Lightweight customizable placeholders for third party content of your website (e.g. Youtube Videos) compatible with the Usercentr

Nov 17, 2022

MusicPlayer-Javascript - How to create a custom music player with vanilla javascript

MusicPlayer-Javascript How to create a custom music player with vanilla javascri

Feb 8, 2022

Simple Music Player App

Разработка музыкального плеера Разработка страницы музыкального плеера с возможностью поиска/выбора альбома для воспроизведения. Адаптивная верстка дл

Apr 10, 2022

A Simple Music Bot Made Using Discord-Player Package - (Beta)

A Simple Music Bot Made Using Discord-Player Package - (Beta)

Our Music Bot A Highly Powerful Music Bot Without Lavalink Which Is Gonna Have Setup, A Specific Text Channel For Bot Command Feature, And DJ System S

Dec 14, 2022

Discord bot made in javascript to play youtube music.

DJS O DJS é um bot para Discord com a capacidade da criar playlists personalizadas, tendo como fonte a biblioteca de músicas do Youtube. Frameworks e

Aug 21, 2022
Comments
Releases(v4.0.1)
Owner
The MUDA Organization
Creating trends, redefining perfection.
The MUDA Organization
It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with buttons. It can play youtube songs, playlists. This bot code was made by Supreme#2401. It uses djs V12

Lofi-Radio-Music-Bot It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with butt

Diwas Atreya 89 Jan 2, 2023
This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library included.

Aim-Player This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library incl

Aim Mikel 2 Jun 27, 2021
A simple HTML5, YouTube and Vimeo player

Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports modern browsers. Checkout the demo - Do

Sam Potts 23.1k Jan 3, 2023
Music-Player - Music player application built with HTML, CSS and vanilla JavaScript

Music-Player Music player application built with HTML, CSS and vanilla JavaScrip

Karthik Umashankar 1 Feb 10, 2022
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Dec 27, 2022
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Jan 8, 2023
SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc.

WordPress-Plugin-SrsPlayer SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc. Usage First, you should get your own video stream

ossrs 3 Jul 27, 2022
SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc.

SRS Player is a video streaming player, supports HLS/HTTP-FLV/WebRTC etc.

ossrs 12 Oct 15, 2022
An online stem player. Inspired by but not affiliated with YEEZY TECH X KANO Stem Player.

Stem Player Online An online stem player. Inspired by but not affiliated with YEEZY TECH X KANO Stem Player. https://stemplayeronline.com See the proj

Luke Weiler 23 Nov 13, 2022
Rule YouTube, Soundcloud and Vimeo player with one API

Polyplayer Polyplayer allows you to rule YouTube's, Soundcloud's and Vimeo's player using one API. Features Playing, pausing, stopping Seek to absolut

Marius 41 Sep 24, 2022