Can I have a mp4 video with transparent background using HTML5 video tag?
I got the solution, we need to run this html in localhost or on server.
How to make a html5 video poster image transparent to see the background image while video is not playing
My solution looks like the following:
<!-- generate an extra button to start the video -->
<button id="button_teaser" onclick="playPause()">Play</button>
<video class="js-player" poster="poster.jpg" controls playsinline preload="none" id="video_teaser" data-plyr-config='{"volume": 0.3, "resetOnEnd": true, "enabled": true, "storage": { "enabled": false }, "quality": { "default": 720 } }'>
<source src="video_360p.mp4" type="video/mp4" size="360">
<source src="video_720p.mp4" type="video/mp4" size="720">
<source src="video_1080p.mp4" type="video/mp4" size="1080">
</video>
<!-- hide video -->
<script>
$('#video_teaser').hide();
</script>
<!-- after clicking the generated play button, hide play button and show video -->
<script>
$(document).ready(function(){
$('#button_teaser').click(function(){
$('#video_teaser').show();
$('#button_teaser').hide();
$('#video_teaser').get(0).play();
});
});
</script>
<!-- after playing video automatically hide video and show play button again -->
<script>
$(document).ready(function(){
$('#video_teaser').on('ended',function(){
$('#video_teaser').hide();
$('#button_teaser').show();
});
});
</script>
Overlaying a transparent background on an embedded video
Here is a fiddle
I used green overlay for the demo.
CSS
.videoContainer {
position: relative;
width: 100%;
height: 100%;
//padding: 20px;
border-radius: 5px;
background-attachment: scroll;
overflow: hidden;
}
.videoContainer video {
min-width: 100%;
min-height: 100%;
position: relative;
z-index: 1;
}
.videoContainer .overlay {
height: 100%;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
z-index: 2;
background: green;
opacity: 0.5;
}
Related Topics
Why Does 'Transform' Break 'Position: Fixed'
Make Input Type="Password" Use Number Pad on Mobile Devices
How to Change a Span to Look Like a Pre with CSS
Overriding CSS Properties for a Specific HTML Element
Responsive Order Confirmation Emails for Mobile Devices
Jenkins Content Security Policy
How to Make a Div with Arrowlike Side Without CSS Border Tricks
CSS Border Color Switch Animation: "From" Color Not Correct
404 Page Not Found - Go Rendering CSS File
How to Hide Autofill Safari Icon in Input Field
Force an Image to Fit and Keep Aspect Ratio
Display Background Color for The Page & Align Texts at Center
Understanding CSS2.1 Specification Regarding Height on Inline-Level Boxes
Horizontal Scrolling with Mouse Wheel in a Div
Twitter Bootstrap: Align Nav-Tabs to Bottom of Div
Responsive Web Design Tips, Best Practices and Dynamic Image Scaling Techniques