简体   繁体   中英

JQuery background video does not cover whole the page

I am using Vide to play a video in the background. Here is the playing div tag.

<div style="width: 1000px; height: 500px;"
  data-vide-bg="path/to/video" data-vide-options="loop: false, muted: false, position: 0% 0%">
</div>

when i change the style to

width: 100%; height: 100%;

The video disappears from the page. I want that video covers all page and I can scroll down.

Why does it happen?

How can I fix it?

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Body background example</title>
<style>
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
}
</style>
</head>
<body data-vide-bg="video/ocean">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../libs/jquery/dist/jquery.min.js"><\/script>')</script>
 <script src="../src/jquery.vide.js"></script>

 </body>
 </html>

This is fine just put scroll bar or use some jquery for scroll purpose.

if you want to cover all with the div and adjusted depending on the size of the screen, this is the code (Important, this is directive to the div):

style="
    position: absolute; 
    z-index: -1;
    top: 0px; 
    left: 0px; 
    bottom: 0px;
    right: 0px; 
    overflow: hidden; 
    -webkit-background-size: cover; 
    background-size: cover; 
    background-image: none; 
    background-position: 50% 50%; 
    background-repeat: no-repeat no-repeat;"

if you want in the body, in the folder examples/body-bg.html is the examples for apply to the body only: https://github.com/VodkaBears/Vide/tree/master/examples

You are using the wrong units of measurement. If you pull the image in via CSS image-background then you can set the image-background-size to the contain property. It will insure that the video completely fits into it container (body, div, span, etc.).

body{
background-image:url(''your-video.mp4');
background-repeat:no-repeat;
image-background-size: contain;
}

Source: w3schools CSS3 background-size Property

You could also try using the height and width but use the vh and vw metrics. It sets the height and width based on the view ports dimensions.

Source: CSS Units

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM