Web Development

Creating a Custom Video Carousel to Display YouTube Videos

We recently completed a project for a customer that required the development of a custom video carousel to show their YouTube videos by category. We wanted a large hero Video on the page and a carousel of other videos in a scroll bar below. It needed to look something like this:


We were surprised to not find one that was flexible enough to suit our design needs, so we decided to build our own.

To display the videos we used the awesome Slick carousel by Ken Wheeler. You can find it here.

Then we organized the clients videos into separate playlists in the YouTube manager.  Doing this creates a unique key for each playlist that we could access. Here is a quick video that shows how to find a YouTube Channels playlist. The playlist ID is the string starting with PL.

To create the initial Hero Video we created a iframe to hold the video. We added controls=0 and shoinfo=0 to hide all of the YouTube controls overlay. Sadly its against YouTube’s use policy to remove the large play button.

[js]$(‘#hero’).html(‘<iframe name=”videoFrame” width=”560″ height=”315″ src=”http://www.youtube.com/embed?listType=playlist&list=”Your playlist ID here”&controls=0&showinfo=0″ theme=”none” modestbranding=”1″ rel=”0″ frameborder=”0″allowfullscreen=””></iframe>’);[/js]

We created navigation buttons for each playlist at the top of the hero video and associated each with a playlist ID.  If the tab is clicked, the event is captured and some javascript does an api call to the corresponding YouTube playlist. That looks something like this:
$(‘.tabs nav ul li a:not(:first)’).click( function(e){
$(‘.tabs nav ul li’).removeClass(‘tab-current’);
var htmlString = ”;
var htmlEmbed = ”;
var channelname = $(this).attr(‘href’).substring(1);
var ytapiurl =’https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=’+channelname+’&key=”Your YouTube API key here”&maxResults=20′;
var requestAjax = $.ajax ({
dataType: ‘json’,
url: ytapiurl,
type: ‘GET’


If the ajax request works, it then works through all the individual videos in the playlist. We then took those videos and stuffed each one into its own Iframe. But first we needed to change out the Hero video with the first video from the new list.
function getYouTubeData(data){
var arr = data.items;
var firstVid = arr[0].contentDetails.videoId;
htmlEmbed += ‘<iframe name=”videoFrame” width=”560″ height=”315″ src=”http://www.youtube.com/embed/’+firstVid+’?controls=0&showinfo=0″ rel=”0″ frameborder=”0″ allowfullscreen=””></iframe>’;

We then looped through the playlist and grabed each video individually, parsed its information and stuffed the results in its own div element. (The Slick Carousel uses div instead of List Items.)
for(var i = 0; i < arr.length; i++){
var snipid = arr[i].contentDetails.videoId;
var xtapiurl = ‘https://www.googleapis.com/youtube/v3/videos?part=snippet&id=’+snipid+’&key=”Your YouTube API key here”‘;
var requestAjax2 = $.ajax ({
dataType: ‘json’,
url: xtapiurl,
type: ‘GET’

function getVideoData(vid){
var vidEmbed = vid.items[0].id;
var vidTitle = vid.items[0].snippet.title;
var vidThumb2 = ‘http://img.youtube.com/vi/’+vidEmbed+’/0.jpg’;
var vidSrcUrl = ‘//www.youtube.com/embed/’+vidEmbed+”;

htmlString += ‘

All those new divs then get stuffed into a parent div.
$(‘#videos’).html(htmlString + ‘


Finally after a short wait for the DOM to finish loading we called the Slick Slider carousel and displayed all of the videos.
}, 1000);

All in all it worked out very well.  The finished product on the clients website can be viewed here.