Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

youtube-background

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

youtube-background

Simple jQuery plugin for embedding YouTube videos as a cover background

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8K
decreased by-9.53%
Maintainers
1
Weekly downloads
 
Created
Source

jquery.youtube-background

Another 100 liner in a form of a jQuery plugin created to facilitate YouTube embeds as a cover background using YouTube Embed API.

I wrote this code several times over the years and never bothered to make it reusable. Now when I needed it again I could not even find where I wrote it last...

Goodbye careless days... I'm getting old...

DEMO HERE ⤻

Usage

Usage is pretty simple, add a data attribute data-youtube containing a full YouTube link or just the YouTube ID.

You can trigger all elements containing the noted attribute with $("[data-youtube]").youtube_background();, or specify your selector, on jQuery document ready event.

P.S. https://www.youtube.com/player_api is injected automatically, only once per script init. I've seen some implementations like Elementor WP plugin that inject it several times, for no reason. Anyway, you're welcome.

Quick Example

    <div id="ytbg" data-youtube="https://www.youtube.com/watch?v=eEpEeyqGlxA"></div>

    <script type="text/javascript">
        jQuery(document).ready(function() {
            $('[data-youtube]').youtube_background();
        });
    </script>

Properties

PropertyDefaultAcceptsDescription
play-buttonfalsebooleanAdds a toggle pause button
mute-buttonfalsebooleanAdds a toggle mute button
autoplaytruebooleanAutoplay loaded video
mutedtruebooleanLoad video muted
looptruebooleanLoop loaded video
mobilefalsebooleanKeep the youtube embed on mobile
load-backgroundtruebooleanFetch background from youtube
pausefalsebooleanAdds a toggle pause button (deprecated)

Noted properties can be added as html attributes as:

  • data-ytbg-play-button
  • data-ytbg-mute-button
  • data-ytbg-autoplay
  • data-ytbg-mooted
  • data-ytbg-loop
  • data-ytbg-mobile
  • data-ytbg-load-background
Example - Properties as HTML attributes
    <div id="ytbg" data-ytbg-play-button="true" data-youtube="https://www.youtube.com/watch?v=eEpEeyqGlxA"></div>

    <script type="text/javascript">
        jQuery(document).ready(function() {
            $('[data-youtube]').youtube_background();
        });
    </script>
Example - Properties as JSON
    <div id="ytbg" data-youtube="https://www.youtube.com/watch?v=eEpEeyqGlxA"></div>

    <script type="text/javascript">
        jQuery(document).ready(function() {
            $('[data-youtube]').youtube_background({
				'play-button': true
			});
        });
    </script>

todo

  • Autoplay property
  • Mute property and button #4
  • Add another wrapper so video can fade in when loaded
  • Add play-pause events
  • Test the execution order
  • Make a unified solution with support for Vimeo, Brightcove, Slate and DailyMotion and HTML5 video, this can also be a new more robust project called video-background

THE END.

Keywords

FAQs

Package last updated on 26 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc