获取背景图像以进行滚动

时间:2016-09-13 05:46:33

标签: html css

我在访问者进入着陆页时运行背景视频。当您向下滚动页面时,视频会保留在原位,但我想更改此视频,以便视频滚动出来。我不知道该怎么做。

这是我的CSS:

video#bgvid { 
    position: fixed;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    -ms-transform: translateX(-50%) translateY(-50%);
    -moz-transform: translateX(-50%) translateY(-50%);
    -webkit-transform: translateX(-50%) translateY(-50%);
    transform: translateX(-50%) translateY(-50%);
    background: url() no-repeat;
    background-size: cover; 
}

.video-container {
    min-height: 100vh;
}
.video-container-bg {
    padding-top: 45vh;
    color: #fff;
}

以下是使用它的HTML:

<div class="video-container">
    <div class="video-container-bg">
        <video playsinline autoplay muted loop poster="{{page.image.url}}" id="bgvid">
                <source src="{{page.video.url}}" type="video/mp4">
        </video>
        <div class="container">
            <div class="row">
                <div class="col-sm-12 col-md-8">
                    <div class="animation-element bounce-up">
                        <h1 class="page-title">{{page.page_title}}</h1>
                        <p class="strapeline">{{page.strapline}}</p>
                        <a class="butt" href="#about-us">Learn More</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

制作position:relative而非固定

&#13;
&#13;
video#bgvid { 
    position: relative;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    -ms-transform: translateX(-50%) translateY(-50%);
    -moz-transform: translateX(-50%) translateY(-50%);
    -webkit-transform: translateX(-50%) translateY(-50%);
    transform: translateX(-50%) translateY(-50%);
    background: url() no-repeat;
    background-size: cover; 
}

.video-container {
    min-height: 100vh;
}
.video-container-bg {
    padding-top: 45vh;
    color: #fff;
}
&#13;
<div class="video-container">
    <div class="video-container-bg">
        <video playsinline autoplay muted loop poster="{{page.image.url}}" id="bgvid">
                <source src="{{page.video.url}}" type="video/mp4">
        </video>
        <div class="container">
            <div class="row">
                <div class="col-sm-12 col-md-8">
                    <div class="animation-element bounce-up">
                        <h1 class="page-title">{{page.page_title}}</h1>
                        <p class="strapeline">{{page.strapline}}</p>
                        <a class="butt" href="#about-us">Learn More</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="video-container">
    <div class="video-container-bg">
        <video playsinline autoplay muted loop poster="{{page.image.url}}" id="bgvid">
                <source src="{{page.video.url}}" type="video/mp4">
        </video>
        <div class="container">
            <div class="row">
                <div class="col-sm-12 col-md-8">
                    <div class="animation-element bounce-up">
                        <h1 class="page-title">{{page.page_title}}</h1>
                        <p class="strapeline">{{page.strapline}}</p>
                        <a class="butt" href="#about-us">Learn More</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="video-container">
    <div class="video-container-bg">
        <video playsinline autoplay muted loop poster="{{page.image.url}}" id="bgvid">
                <source src="{{page.video.url}}" type="video/mp4">
        </video>
        <div class="container">
            <div class="row">
                <div class="col-sm-12 col-md-8">
                    <div class="animation-element bounce-up">
                        <h1 class="page-title">{{page.page_title}}</h1>
                        <p class="strapeline">{{page.strapline}}</p>
                        <a class="butt" href="#about-us">Learn More</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
&#13;
&#13;
&#13;