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

Overview

Vimeo LazyLoad

LazyLoad Embed Vimeo 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/vimeo-lazyload.git
  • Install with Composer: composer require the-muda-organization/vimeo-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

vi-lazyload/
 │
 └─ dist/
    │
    ├── css/
    │   ├── vi-lazyload.css
    │   └── vi-lazyload.min.css
    │
    └── js/
        ├── vi-lazyload.js
        └── vi-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 vi-lazyload.js
  3. Change settings:
    • settings_thumb_base_url to custom URL where your thumbnails are located.
  4. Minify JavaScript and place it in vi-lazyload.min.js.
  5. Add CSS and JavaScript to your project:
    <link href="https://example.com/vi-lazyload/2.x.x/css/vi-lazyload.min.css" rel="stylesheet">
    <script src="https://example.com/vi-lazyload/2.x.x/js/vi-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 Vimeo ID of your movie, example: 272532681
  2. Add the folowing code to embed a video:
<div class="vi-lazyload" data-id="272532681" data-thumb="" data-logo="3"></div>
  1. Name your thumbnail using Vimeo ID 272532681.jpg - to use other file types change settings in JavaScript
  2. Place your thumbnail in a folder set in JavaScript

Features

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

You can add additional style like border, box-shadow etc. or Bootstrap classes like img-thumbnail, shadow etc.
data-id="272532681" Vimeo 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 272532681.jpg and add custom suffix.

For 3 thumbnails make 272532681--1.jpg, 272532681--2.jpg and 272532681--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" Vimeo logo color. You can customize it in CSS.

0 = none - logo will not be added by JavaScript,
1 = blue,
2 = dark,
3 = white.

CSS Classes

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

FAQ

  • Can I use Vimeo domain to get thumbnails?
    • Not as easy as on Youtube. Vimeo doesn't use video id for its thumbnails. You need to use Vimeo API to get URL of thumbnail.
  • Can I use Vimeo lazyload with other frameworks like Bootstrap?
    • Yes you can! There should be no conflict with other frameworks.
  • Can I embed video players other than Vimeo?

Versioning

Vimeo 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...

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

Nov 13, 2022

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

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

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

Jan 2, 2023

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

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
Comments
  • [Feature request] specify an external URL

    [Feature request] specify an external URL

    Instead of hacking settings_thumb_base_url in the code and having to create a custom file on the server specific for this task simply add a data-img-url="" to specifiy any full URL

    enhancement 
    opened by badpenguin 2
  • Thumbnail is full width, but video is not?

    Thumbnail is full width, but video is not?

    Hello

    I have an issue where the lazyloaded video will not be the same width as the thumbnail. This makes the video have a left and right border showing some of the thumbnail underneath.

    Example: https://i.imgur.com/74ctuVZ.png This also happens on the demo: https://i.imgur.com/7cD0Uuk.png

    I am pretty sure that the iFrame thinks its 100% of the thumbnail, but the actual video that is playing is not.

    I tried fiddeling around with some calculations of padding-bottom but didn't seem to work.

    How would I get the actual video player to be the same size as the thumbnail?

    bug 
    opened by BE-CH 2
  • Sorry This video does not exist.

    Sorry This video does not exist.

    After finding out Vimeo has had issues with its embed code they have made some changes to how the videos are played. They now require a url parameter for example: https://player.vimeo.com/video/00000000?h=0000000abc. for any new videos being uploaded.

    All my old vimeo videos still work fine. However any new videos I have uploaded haven't worked when lazy loading them on my website.

    To fix this issue I have added a data-pram attribute to div.vi-lazyload and changed the js file to build the new formatted url. See below.

    /********************************************************************
    ************************** MAIN VARIABLES ***************************
    *********************************************************************/
    var vimeo = document.querySelectorAll('.vi-lazyload'),
    
        vimeo_observer,                                                 //Intersection Observer API
        
        template_wrap,
        template_content,
        template_playbtn,
        template_logo,
        template_iframe,
        
        settings_observer_rootMargin    = '200px 0px',                  //Intersection Observer API option - rootMargin (Y, X)
        settings_thumb_base_url         = 'https://raw.githubusercontent.com/the-muda-organization/vimeo-lazyload/master/demo-img/',     //Base URL where thumbnails are stored
        settings_thumb_extension        = 'webp';                       //Thumbnail extension
        
    
    
    /********************************************************************
    ************************ IF ELEMENTS EXIST **************************
    *********************************************************************/
    if(vimeo.length > 0){
        
        //create elements
        template_wrap       = document.createElement('div');
        template_content    = document.createElement('div');
        template_playbtn    = document.createElement('div');
        template_logo       = document.createElement('a');
        template_iframe     = document.createElement('iframe');
        
        //set attributes
        template_wrap.classList.add('vi-lazyload-wrap');
        template_content.classList.add('vi-lazyload-content');
        
        template_playbtn.classList.add('vi-lazyload-playbtn');
        
        template_logo.classList.add('vi-lazyload-logo');
        template_logo.target = '_blank';
        template_logo.rel    = 'noreferrer';
        
        template_iframe.setAttribute('allow','autoplay;fullscreen;picture-in-picture');
        template_iframe.setAttribute('allowfullscreen','');
        
        
        /********************************************************************
        ********************* INTERSECTION OBSERVER API *********************
        *********************************************************************/
        vimeo_observer = new IntersectionObserver(function(elements){
        
            elements.forEach(function(e){
                
                //VARIABLES
                var this_element    = e.target,
                    
                    this_wrap,
                    this_content,
                    this_playbtn,
                    this_logo,
                    this_iframe,
                    
                    this_data_id    = e.target.dataset.id,
                    this_data_pram    = e.target.dataset.pram,
                    this_data_thumb = e.target.dataset.thumb,
                    this_data_logo  = e.target.dataset.logo;
                
                
                //if element appears in viewport
                if(e.isIntersecting === true){
                    
                    //wrap
                    this_wrap = template_wrap.cloneNode();
                    this_element.append(this_wrap);
                    
                    //content
                    this_content = template_content.cloneNode();
                    this_wrap.append(this_content);
                    
                    //background-image
                    this_content.style.setProperty('--vi-lazyload-img','url("' + this_data_thumb +'")');
                    
                    //play btn
                    this_playbtn = template_playbtn.cloneNode();
                    this_content.append(this_playbtn);
                    
                    //logo link
                    if(this_data_logo !== '0'){
                        this_logo       = template_logo.cloneNode();
                        this_logo.href  = 'https://vimeo.com/' + this_data_id;
                        this_content.append(this_logo);
                    }
                    
                    //onclick create iframe
                    this_playbtn.addEventListener('click',function(){
                        this_iframe     = template_iframe.cloneNode();
                        this_iframe.src = 'https://player.vimeo.com/video/' + this_data_id + '?' + this_data_pram + '&autoplay=1&autopause=0';
                        this_content.append(this_iframe);
                    });
                    
                    //Unobserve after image lazyloaded
                    vimeo_observer.unobserve(this_element);
                    
                    //LOG
                    //console.log('DONE - ' + this_data_id);
                }
                
            });
            
        },{
            rootMargin: settings_observer_rootMargin,
        });
        
        
        /********************************************************************
        ********************* ITERATE THROUGH ELEMENTS **********************
        *********************************************************************/
        vimeo.forEach(function(e){
            
            //Intersection Observer API - observe elements
            vimeo_observer.observe(e);
            
        });
    }
    

    })();

    bug 
    opened by JackVanson 1
Releases(v2.1.0)
  • v2.1.0(Mar 23, 2021)

    CSS:

    • Optimized Vimeo logo (7.25KB smaller CSS) - 3 different color variants were changed to a single color in CSS variable. CSS filter is used to generate white and dark variants. Similar solution is used in Bootstrap-5 CSS (see .btn-close-white).
    • Fixed SVG - removed charset utf-8 from each SVG in background-image as it is not required.

    JS:

    • Updated Vimeo iframe allow="" attribute - added picture-in-picture
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Jun 20, 2020)

    CSS:

    • changed layout so that container maintains 16/9 ratio even if JS not loaded
    • thumbnails are loaded as background-image using style attributes and CSS variables.

    JS:

    • rebuilt from scratch
    • added lazyload (using Intersection Observer API - https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
    • (#2) - vimeo logo & link not added when data-logo="0"
    • important settings moved to variables at the beginning of JS file

    OTHER:

    • improved documentation
    • DEMO - Bootstrap updated to v5
    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Feb 8, 2020)

Owner
The MUDA Organization
Creating trends, redefining perfection.
The MUDA Organization
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
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
A custom element (web component) for the Vimeo player.

<vimeo-video> A custom element (web component) for Vimeo. The element API matches the HTML5 <video> tag, so it can be easily swapped with other media,

Wesley Luyten 4 Dec 28, 2022
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
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
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion

ReactPlayer A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia, M

Pete Cook 7.2k Jan 4, 2023
▶️ Streams a list of tracks from Youtube, Soundcloud, Vimeo...

PlayemJS PlayemJS is a front-end JavaScript component that manages a audio/video track queue and plays those tracks sequentially. It can currently pla

Adrien Joly 90 Nov 27, 2022
Recap let's you recap on your favourite social network videos by downloading them on your devices, from the range of YouTube, SoundCloud, Facebook, Twitter, Instagram, TikTok, Vimeo, Dailymotion, VK, or AOL.

Recap A Social Network Video Downloader Recap let's you recap on your favourite social network videos by downloading them on your devices, from the ra

John Oladele 4 Sep 24, 2022
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