我正在尝试用短视频替换标题背景图片。我经常搜索但找不到合适的解决方案。
我可以找到这个article,但由于我仍然是网络开发的新手,所以无法做到这一点。
任何人都可以帮我解决代码中所需的更改。
以下是我Fiddle的链接。
HTML:
<section>
<header>
<h1><strong>Header</strong></h1>
<p>Lorem Ipsum</p>
</header>
<footer>
<a href="#first" class="button scrolly">US</a>
<a href="#second" class="button scrolly">UK</a>
<a href="#fifth" class="button scrolly">India</a>
<a href="#third" class="button scrolly">China</a>
<a href="#fourth" class="button scrolly">Mongolia</a>
</footer>
</section>
CSS:
.dark {
color: #aaa;
color: rgba(255, 255, 255, 0.65);
}
#header {
position: relative;
margin: 0;
background-image: url("http://www.mygreencity.in/images/slider/1.jpg");
background-size: auto, cover;
background-position: top left, center center;
background-repeat: repeat, no-repeat;
padding: 14em 0 14em 0;
text-align: center;
color: #fff;
}
#header header h1 {
font-size: 2.25em;
line-height: 1.25em;
margin-bottom: 0;
}
#header header p {
margin-top: 1.25em;
font-weight: 100;
padding: 0;
font-size: 1.25em;
line-height: 1.5em;
text-align: center;
}
#header footer {
padding-top: 1.5em;
}
input[type="button"],
input[type="submit"],
input[type="reset"],
button,
.button {
-moz-transition: all 0.25s ease-in-out;
-webkit-transition: all 0.25s ease-in-out;
-ms-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
-webkit-appearance: none;
position: relative;
display: inline-block;
background: #3d3d3d;
padding: 0.85em 3em 0.85em 3em;
border-radius: 0.25em;
cursor: pointer;
border: 0;
color: #fff;
text-align: center;
text-decoration: none;
}
input[type="button"]:hover,
input[type="submit"]:hover,
input[type="reset"]:hover,
button:hover,
.button:hover {
background: #4f4f4f;
}
input[type="button"].alt,
input[type="submit"].alt,
input[type="reset"].alt,
button.alt,
.button.alt {
color: inherit;
box-shadow: inset 0 0 0 1px #e6e6e6;
background: none;
}
input[type="button"].alt:hover,
input[type="submit"].alt:hover,
input[type="reset"].alt:hover,
button.alt:hover,
.button.alt:hover {
background: rgba(0, 0, 0, 0.025);
}
.dark input[type="button"],
.dark input[type="submit"],
.dark input[type="reset"],
.dark button,
.dark .button {
background: rgba(255, 255, 255, 0.15);
box-shadow: inset 0 0 0 1px #fff;
color: #fff;
}
.dark input[type="button"]:hover,
.dark input[type="submit"]:hover,
.dark input[type="reset"]:hover,
.dark button:hover,
.dark .button:hover {
background: rgba(255, 255, 255, 0.25);
}
.dark input[type="button"].alt,
.dark input[type="submit"].alt,
.dark input[type="reset"].alt,
.dark button.alt,
.dark .button.alt {
background: none;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.dark input[type="button"].alt:hover,
.dark input[type="submit"].alt:hover,
.dark input[type="reset"].alt:hover,
.dark button.alt:hover,
.dark .button.alt:hover {
background: rgba(255, 255, 255, 0.15);
box-shadow: inset 0 0 0 1px #fff;
}
答案 0 :(得分:0)
您可以使用jquery videoBG插件:http://syddev.com/jquery.videoBG/
或者您可以添加以下代码:https://jsfiddle.net/5oxjuyum/1/
当浏览器不支持视频时,会显示替代图像。
<强> HTML 强>
<video id="video" autoplay>
<source src="video.mp4" type="video/mp4" />
<img id="alternative" src="http://www.mygreencity.in/images/slider/1.jpg" />
</video>
<强> CSS 强>
#video, #alternative {
width: 100%;
height: 100vh;
object-fit: cover;
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}
答案 1 :(得分:0)
https://css-tricks.com/snippets/jquery/append-site-overlay-div/
$(function() {
var docHeight = $(document).height();
$("body").append("<div id='overlay'>VIDEO TAG</div>");
$("#overlay")
.height(docHeight)
.css({
'opacity' : 0.4,
'position': 'absolute',
'top': 0,
'left': 0,
'background-color': 'black',
'width': '100%',
'z-index': 5000
});
});