JSFiddle - React, Tailwind, and code Playground
HTML
<span class="switch button allofthelights">Выключить свет</span>
<div class="switch"></div>
<iframe class="video" width="560" height="315" src="https://www.youtube.com/embed/h4TLfeXccJY" frameborder="0" allowfullscreen></iframe>
JavaScript
/*
* Allofthelights.js
* Version: 2.0
* Description: jQuery plugin to turn off the light and enjoy your videos !
* Licence: MIT
* Infos: http://www.megaptery.com/allofthelights/
* Author: Pierre VION - http://www.pierrevion.fr/
*/
(function ($) {
$.fn.allofthelights = function (options) {
var defaults = {
color: 'black',
opacity: '0.9',
z_index: '10',
switch_selector: 'switch',
delay_turn_on: 400,
delay_turn_off: 400,
scrolling: true,
is_responsive: true,
custom_player: null
};
var options = $.extend(defaults, options);
var $body = $('body');
var $elements = [];
var switch_selector = '#'+options.switch_selector+', .'+options.switch_selector;
this.each(function() {
var $this = $(this);
$elements.push($this);
});
if (options.is_responsive) {
var selectors = [
"iframe[src*='player.vimeo.com']",
"iframe[src*='www.youtube.com']",
"iframe[src*='www.dailymotion.com']",
"iframe[src*='www.kickstarter.com']",
"object",
"embed"
];
if (options.custom_player) {
selectors.push(options.custom_player);
}
var $all_videos = $(this).parent().find(selectors.join(','));
var style =
'<style type="text/css"> \
.fluid_width_video_wrapper { \
width: 100%; \
position: relative; \
padding: 0; \
} \
.fluid_width_video_wrapper iframe, \
.fluid_width_video_wrapper object, \
.fluid_width_video_wrapper embed { \
position: absolute; \
top: 0; \
left: 0; \
width: 100%; \
height: 100%; \
} \
</style>';
$body.append(style);
$all_videos.each(function(){
var $this = $(this);
if (this.tagName.toLowerCase() == 'embed' && $this.parent('object').length || $this.parent('.fluid_width_video_wrapper').length) { return; }
var height = ( this.tagName.toLowerCase() == 'object' || $this.attr('height') ) ? $this.attr('height') : $this.height(),
width = $this.attr('width') ?...