load a youtube video in a fancybox modal

With just a couple of lines of js and html you can load your video links in a modal lightbox.

Get the latest version of the fancybox scripts (just the links) from here: https://cdnjs.com/libraries/fancybox

 

JS

jQuery(document).ready(function() {

	$(".youtube").fancybox({
	    type: "iframe"
	});

});

HTML

<!-- Add links to JQuery and Fancybox -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" integrity="sha256-Vzbj7sDDS/woiFS3uNKo8eIuni59rjyNGtXfstRzStA=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js" integrity="sha256-yt2kYMy0w8AbtF89WXb2P1rfjcP/HTHLT7097U8Y5b8=" crossorigin="anonymous"></script>

<!-- Add your link to the youtube video with the class .youtube  -->
<p>
  <a href="https://www.youtube.com/embed/2-oBj5kj_K0" class="youtube btn btn-primary">Click this buttons to load the video.</a>
</p>

Working Result

Click this buttons to load the video.

Page Views

This page has been viewed 129 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown