Skip to content

Instantly share code, notes, and snippets.

@mattkenefick
Created January 18, 2014 03:11
Show Gist options
  • Save mattkenefick/8485639 to your computer and use it in GitHub Desktop.
Save mattkenefick/8485639 to your computer and use it in GitHub Desktop.
Custom posters for YouTube and Vimeo
<!DOCTYPE html>
<html>
<head>
<title>Posters Test for Video</title>
<style>
.group {
height: 250px;
outline: 1px solid red;
position: relative;
width: 500px;
}
iframe,
embed {
left: 0;
height: 100%;
position: absolute;
top: 0;
width: 100%;
z-index: 5;
}
.poster {
background: url('poster.png') center center;
background-size: cover;
bottom: 0;
left: 0;
opacity: 0.5;
pointer-events: none;
position: absolute;
right: 0;
top: 0;
z-index: 10;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<h2>YouTube - IFrame</h2>
<div class="group">
<iframe width="560" height="315" src="//www.youtube.com/embed/2HjTs-y-ZQo" frameborder="0" allowfullscreen></iframe>
<div class="poster"></div>
</div>
<h2>YouTube - Embed</h2>
<div class="group">
<embed src="//www.youtube.com/v/RWDrdAJMcRs?hl=en_US&amp;version=3" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed>
<div class="poster"></div>
</div>
<h2>Vimeo - IFrame</h2>
<div class="group">
<iframe id="vimeo" src="//player.vimeo.com/video/72316750?api=1&amp;player_id=vimeo&amp;title=0&amp;byline=0&amp;portrait=1&amp;badge=0&amp;color=ffffff&amp;wmode=opaque" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<div class="poster"></div>
</div>
<h2>Vimeo - Embed</h2>
<div class="group">
<embed src="http://vimeo.com/moogaloop.swf?clip_id=76495339&amp;force_embed=1&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="281"></embed>
<div class="poster"></div>
</div>
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
<script>
var $last_hover;
// for embedded ones
$('.group, iframe').mousedown(function() {
// hide poster
$(this).find('.poster').fadeOut();
});
// note what we hover
$('.group').hover(function() {
$last_hover = $(this);
}, function() {
$last_hover = null;
});
// iframe is active by click
$(window).blur(function() {
$last_hover && $last_hover.find('.poster').fadeOut();
});
// specific video
var vimeo = $('#vimeo')[0],
$fvimeo = $f(vimeo);
$fvimeo.addEvent('ready', function() {
$fvimeo.addEvent('play', function() {
$(vimeo).next('.poster').fadeOut();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment