html5 video tag Complete Guide

Basically in this tutorial we are explaining all kind of thing about html5 video tag.
I came up with this idea and it works perfectly for me so i thought i share with you may be it will help of you.
So basically we want to get tour of the HTML5 video tag how to resize poster to the videos actual size. Here i am writing some examples of HTML5 video tag.

HTML5 video hide controls until hover

Here i am showing video player controls on mouse hover and hide on mouse leave see below example.

// HTML Code
<video width="100%" height="100%" id="VideoId">
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

// JavaScript Code
<script>
jQuery('#VideoId').hover(function toggleControls() {
    this.setAttribute("controls", "controls");
});
jQuery('#VideoId').mouseout(function(){
    this.removeAttribute("controls")
});
</script>

How to add video thumbnail in html5 video tag

Yes here is a way to set thumbnail image on HTML5 video if you want to see some pictures before play then you should follow the below example and code.
Add poster=”videothumbnail.png” to the video tag.

<video width="100%" height="100%" poster="videothumbnail.png" id="VideoId" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

How to set HTML5 video tag thumbnail with 100% width

You can use simply set preload=”none” attribute to make VIDEO background visible. And you can use background-size: cover below is a example.

// HTML Code
<video width="100%" height="100%" poster="videothumbnail.png" preload="none" id="VideoId" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

// CSS Code
<style>
#VideoId {
    background: transparent url('videothumbnail.png') 50% 50% / cover no-repeat ;
}
</style>

Without adding controls how to play video of html5 video tag

Here i am showing example for how can we play video without adding controls attribute in video tag using couple of lines JavaScript code.

// HTML Code
<video width="470" height="255" poster="placeholder.png" onclick="this.play()" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
    <embed src="video.swf" width="470" height="255">
    </object>
</video>

// JavaScript Code
<script>
var VideoId = document.getElementById('VideoId');
function videoPausePlayHandler(e) {
    if (e.type == 'playing') {
        //add controls
        VideoId.setAttribute("controls","controls");
    } else if (e.type == 'pause') {
        //remove controls
        VideoId.removeAttribute("controls");
    }
}
//Add event listeners
VideoId.addEventListener('playing', videoPausePlayHandler, false);
VideoId.addEventListener('pause', videoPausePlayHandler, false);
</script>

IF YOU LIKE THIS TUTORIAL DON’T FORGET SHARE WITH YOUR FRIENDS!

Leave a Reply

Related Posts: You may like

How To Create a Modal Popup With CSS and JavaScript

Get Latitude Longitude from Address

cookie policy popup

How to make a sticky sidebar on scroll

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.