Skip to content

Instantly share code, notes, and snippets.

@diVineProportion
Created October 20, 2021 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diVineProportion/25e40f7dc999b8dc2082e1b575fc7a18 to your computer and use it in GitHub Desktop.
Save diVineProportion/25e40f7dc999b8dc2082e1b575fc7a18 to your computer and use it in GitHub Desktop.
HTML5 Video Play on Hover

HTML5 Video Play on Hover

Play an HTML5 Video on hover using gifycat.

Combine with Video url (vimeo/youtube) to grab thumbnail

A Pen by Andrea Perazzi on CodePen.

License.

<!--
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://giant.gfycat.com/VerifiableTerrificHind.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>
var cip = $(".video").hover( hoverVideo, hideVideo );
function hoverVideo(e) {
$('video', this).get(0).play();
}
function hideVideo(e) {
$('video', this).get(0).pause();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment