Last active
August 7, 2020 01:09
-
-
Save robdecker/5888513 to your computer and use it in GitHub Desktop.
[Embed YouTube & Vimeo videos in a Colorbox popup] Requires http://www.jacklmoore.com/colorbox/ #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
$("#content a[href*='vimeo.com']").each(function() { | |
$this = $(this); | |
var href = $this.attr('href'); | |
var vimeoId = href.split('/').pop(); | |
$this.colorbox({ html: function() { | |
var iframe = '<iframe width="853" height="480" src="http://player.vimeo.com/video/' + vimeoId + '?autoplay=1" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; | |
var output = "<div style='line-height: 0px; overflow: hidden;'>" + iframe + '</div>'; | |
return output; | |
}}); | |
}); | |
$("#content a[href*='youtube.com']").each(function() { | |
var $this = $(this); | |
var href = $this.attr('href'); | |
var youtubeId = href.split('=').pop(); | |
$this.colorbox({ html: function() { | |
var iframe = '<iframe width="853" height="480" src="http://www.youtube.com/embed/' + youtubeId + '?autoplay=1" frameborder="0" allowFullScreen></iframe>'; | |
var output = "<div style='line-height: 0px; overflow: hidden;'>" + iframe + '</div>'; | |
return output; | |
}}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Rob,
A bit smarter way to do that:
And even some optimization for smaller screens: