Video play on hover
by m4xout
HTML
<!--
Data: https://gfycat.com/cajax/get/VerifiableTerrificHind
Source: https://www.youtube.com/watch?v=nZcejtAwxz4
More info on youtube api for thumbnails: http://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
-->
<div id="videosList">
<div class="video">
<video class="thevideo" loop preload="none">
<source src="https://cdn.shopify.com/s/files/1/2276/2489/t/2/assets/PLAYWAVE_SEQUENCE_1_V4.mp4" type="video/mp4">
<source src="https://giant.gfycat.com/VerifiableTerrificHind.webm" type="video/webm">
Your browser does not support the video tag.
</video>
</div>
Hover mouse over video. Desktop only [ Obviously! ;) ]
</div>
CSS
#videosList {
max-width: 600px;
/* overflow: hidden;*/
}
.video {
background-image: url('https://img.youtube.com/vi/nZcejtAwxz4/maxresdefault.jpg');
height: 330px;
width: 600px;
margin-bottom: 50px;
}
/* Hide Play button + controls on iOS */
video::-webkit-media-controls {
display:none !important;
}
JavaScript
var figure = $(".video").hover( hoverVideo, hideVideo );
function hoverVideo(e) {
$('video', this).get(0).play();
}
function hideVideo(e) {
$('video', this).get(0).pause();
}