How to Set a video as a webpage background and a webpage background for a video

Source: Internet
Author: User

How to Set a video as a webpage background and a webpage background for a video
Sometimes adding an animated background to a webpage will make the webpage look different.

Step 1: Prepare

To do this, we must first prepare a video.

Step 2: introduce video in html

Here we need to use the video/tag, and then write the video path in the source, autoplay is used to make it play automatically, muted is used to mute it, loop is loop playback, if you are willing to add, add, and drop.

<div class="videocontainer"><video class="fullscreenvideo" poster="__ROOT__/Themes/tdt/Asset/images/loginbg.jpg" id="bgvid" playsinline="" autoplay="" muted="" loop=""><source src="__PUBLIC__/video/loginbg.mp4" type="video/mp4"></video></div>

Step 3: Set css and adjust the video to adapt to the screen 

The above steps cannot meet our needs. At this time, we will find a scroll bar, and the video will block the content we want to display. But this is far from the result we want, what about me?

.fullscreenvideo {position: absolute;    top: 50%;    left: 50%;    min-width: 100%;    min-height: 100%;    width: auto;    height: auto;    z-index: -100;    -webkit-transform: translateX(-50%) translateY(-50%);    transform: translateX(-50%) translateY(-50%);    -webkit-transition: 1s opacity;    transition: 1s opacity;}.videocontainer{    position: fixed;    width: 100%;    height: 100%;    overflow: hidden;    z-index: -100;}.videocontainer:before{    content: "";    position: absolute;    width: 100%;    height: 100%;    display: block;    z-index: -1;    top: 0;    left: 0;    background: rgba(25,29,34,.65);}

Step 4: js controls video playback speed

You can use the playbackRate attribute of video to control the playback speed of video. To make the background video play slowly, add the following javascript

<script>    var video= document.getElementById('v1');    video.playbackRate = 0.5;</script>

Okay, go and set your own cool background.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.