<h2>jQuery Featured Media Tabs</h2>
This is a custom jQuery plugin to display and load youtube videos. This plugin was built from a previous plugin that I built <a href="http://jsfiddle.net/RyanBrackett/7ZJtC/">here</a>. This plugin is completely fluid responsive. You can specify which tab/video will be active on load. When the page loads, only the specified video iframe will load. The other video iframes use an alternate custom attribute that holds the iframe source without loading it, making this great for mobile. The thumbnails are pulled from YouTube via video ID and are styled to remove black borders. When you click on a thumbnail, the corresponding video begins to play. When you click another thumbnail, the previous video stops.
<br/>
<br/>
<!-- start FEATURED MEDIA TABS -->
<div class="featured-media">
<div id="page-tabs">
<div class="loader"></div>
<ul id="panels">
<!-- start PANEL -->
<li>
<div class="media-wrapper">
<iframe src-original="//www.youtube.com/embed/YfG2_Gy2p0w?hd=1&rel=0&autohide=1&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</li>
<!-- end PANEL -->
<!-- start PANEL -->
<li>
<div class="media-wrapper">
<iframe src-original="//www.youtube.com/embed/XonxivqZCdE?hd=1&rel=0&autohide=1&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</li>
<!-- end PANEL -->
<!-- start PANEL -->
<li>
<div class="media-wrapper">
<iframe src-original="//www.youtube.com/embed/r5AbvBn-q-o?hd=1&rel=0&autohide=1&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</li>
<!-- end PANEL -->
<!-- start PANEL -->
<li>
<div class="media-wrapper">
<iframe...
//* start FEATURED MEDIA TABS
// jQuery Page Tabs // By Ryan Brackett & Jeremy Clements
var selectedTab = 0; //Set which video you want active on load
var activePanel = selectedTab + 1; // This corrects the numerology from a 0 being the start to 1
// Add classes and ids to tabs and panels for unique styling
$("#tabs").children().each(function (i) {
i = i + 1;
$(this).attr('id', "tab-" + i).addClass("tab");
});
$("#panels").children().each(function (i) {
i = i + 1;
$(this).attr('id', "panel-" + i).addClass("panel");
});
$('#tabs li:nth-child(3n)').addClass('third');
$('#tabs > li')
.eq(0).addClass('first').end()
.eq(-1).addClass('last').end();
// Activate first tab/panel group on load
$("#tabs").children().eq(selectedTab).addClass("xactive");
$("#panels").children().eq(selectedTab).addClass("xactive");
// Activate & deactivate tab/panel groups on click
$("#tabs > li").click(function () {
$("#tabs > li, #panels > li").removeClass("xactive");
$(this).toggleClass('xactive');
$("#panels > li").eq($(this).index()).toggleClass('xactive');
// LOADING VIDEOS & STOP PREVIOUS VIDEO
$("#panels > li").find('iframe').attr('src', "").fadeToggle();
$(".loader").fadeTo("slow", 0);
var active_vid = $("#panels > li").eq($(this).index()).find('iframe'),
src_orig = $(active_vid).attr('src-original')
$(active_vid).hide().attr('src', src_orig + '&autoplay=1').fadeToggle();
$(".loader").fadeTo("slow", .5);
});
// This shows the desired load video as specified at the top
var src_orig = $("#panel-" + activePanel).find('iframe').attr('src-original');
$("#panel-" + activePanel).find('iframe').attr('src', src_orig);
//* end FEATURED MEDIA TABS
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.