|
|
I initially wanted to have only one div to cover the entire document and to play with the video iframe's z-index. Unfortunately I encountered several problems with some players : it worked with YouTube, but not with Dailymotion, etc. I therefore decided to make a new script that would work with any player.
Alloffthelights.js calculates the video's offset and creates four div in position:absolute wrapped around it. The offset is recalculated when the light is turned on or the window resized.
Step 1 - Link to resources
Add these links (jQuery 1.7+, Allofthelights.js core CSS and JS files) to your page. You could choose to have the jQuery file hosted on your server but, hey, Google does it for you :
Step 2 - Add the video and the switch
Give the video iframe an id and place the switch button anywhere you like on the page (remember, its id must match the switch_id option). When the light is off, the plugin will add the suffix '_off' to the switch id so you can customize it (have a look at allofthelights.css).
Step 3 - Call Allofthelights.js
Call the JS function on your video frame... and there you go !
$(document).ready(function() {
$("#video").allofthelights();
});
| Keydefault value | Description |
|---|---|
| color'#000000' | Defines the background color. |
| opacity'0.9' | Defines the background opacity. |
| z_index'10' | Defines the background's z-index. |
| switch_id'switch' | Defines the switch button's CSS id. |
| animation'fade' | Defines the animation type ('fade' or 'none'). |
| delay_turn_on400 | Defines the delay before the animation starts when turning the light on. |
| delay_turn_off400 | Defines the delay before the animation starts when turning the light off. |
| scrollingtrue | Allows disable scrolling when the light is on if value is false. |
| clickable_bgfalse | Allows the user to click the background to turn the light back on. |
| is_responsivetrue | Enables responsive video. |
| custom_playernull | Only available when is_responsive = true. Allows the use of a custom player. Specify your video vendor selector. |
$(document).ready(function() {
$("#video").allofthelights({
'opacity': '0.7',
'delay_turn_on': '3000',
'clickable_bg': true,
'custom_player': "iframe[src^='http://mycoolvideosite.com'], iframe[src^='http://myviiids.com']"
});
});
Due to the use of media queries, Allofthelights.js works better with modern browsers. The script has been tested on Chrome 21.0, Firefox 15, Opera 12.0, Safari 4.0, IE7, IE8 and IE9.
Note : surprisingly, the responsive option doesn't quite work with Firefox 13 to 15. Nevertheless it does work with version 12.
Version 1.0 (07/09/2012)
Alloffthelights.js was created by Pierre Vion. It uses Chris Coyier's FitVids.js for responsive video. A big thanks to Julien Guyomard for his help on code optimization.
Allofthelights.js is a jQuery plugin built by Kanye West that allows to switch off the light, for your videos to stand out. Give it a try by clicking the switch next to the video. Bear in mind this is a first version.
Licensed under the MIT license
Website © 2012 - Built with Foundation CSS framework - Megaptery.com