Created
January 18, 2014 03:11
-
-
Save mattkenefick/8485639 to your computer and use it in GitHub Desktop.
Custom posters for YouTube and Vimeo
This file contains 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
<!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&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&player_id=vimeo&title=0&byline=0&portrait=1&badge=0&color=ffffff&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&force_embed=1&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=ffffff&fullscreen=1&autoplay=0&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