我正在尝试创建类似this的网页,其中视频用作背景,并且当用户向上和向下滚动文本/背景视频时,相应地更改以便讲述故事。
现在播放视频是唯一有效的方法。视频将按预期加载和播放。但是,<div>
元素只是逐个堆叠在视频下方。当用户点击页面上的任意位置时,我希望文本从底部向上滚动,一旦它们到达页面上与前一个文本相同的位置就完成滚动...但是我没有&#39;我认为我正确使用.animate()
功能。
这似乎相对容易做到,所以这是我无可否认的首次尝试。
小提琴:http://jsfiddle.net/f06w76bv/
<!DOCTYPE html>
<html>
<head>
<style>
.textConatiner{
position: absolute;
background-color: rgba(0, 0, 0, 0.9);
color: #fff;
left:10%;
}
video.bgvid{
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
background: url(TurbineStill.png) no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<video autoplay loop poster="TurbineStill.png" class="bgvid">
<source src="Turbine.mp4" type="video/mp4">
</video>
<section>
<div class="textConatiner" id="one" style="top:50%;">
<h2>Video Backgrounds One</h2>
</div>
</section>
<section>
<div class="textConatiner" id="two" style="top:150%;">
<h2>Video Backgrounds One</h2>
</div>
</section>
</body>
<script src="js/jquery-1.11.1.js"></script>
<script>
$(document).ready(function () {
$(document).click(function () {
var myDiv = $("#two");
var scrollto = myDiv.offset().top + (myDiv.height() / 2);
myDiv.animate({ scrollTop: scrollTo }, 1000);
});
});
</script>
</html>
修改
通过将position
添加到div容器,我可以在页面加载时将原始div位置准确地放在我想要的位置。但是,我仍然无法使用animate
方法将第二个div
从下面移到页面中。
答案 0 :(得分:1)
你的问题并不是全新的,它只是一堆问题。
首先 - 为了您的定位,您将能够像使用任何DOM元素一样使用纯CSS。例如,教程就在W3Schools。
使用JQuery滚动到元素在this stackoverflow-Question中得到了解答。
另一个关于通过滚动移动视频的stackoverflow问题可以找到here。