我在做一个着陆视频部分,其中有一个视频播放在背景中,根据视频,有一些文本将改变与视频有关的视频,取决于视频的时间。文本动画使用的是关键帧。我已经开始工作了,但是我被困在了一个点上,那就是,在循环过程中延迟。
在窗口负载(视频的启动)上,一切正常工作,但是当视频结束并返回回循环时,视频在循环后重新启动大约有1秒或几秒的延迟。当视频重新启动文本更改时,“这是我的实际问题”,关键帧中的文本更改被延迟,迭代计数被设置为无穷大。文本与视频第二次不匹配。当我停留在那一段,像一分钟,视频是不匹配的文字幻灯片。
当视频开始第二次循环时,是否有任何方法可以延迟使用CSS或jQuery的动画而文本延迟。
下面是我正在处理的代码。
body {
background-color: #02001b;
}
.wrapper {
position: relative;
width: 1455px;
height: 799px;
margin: 0 auto;
}
.header-section section {
width: 45%;
height: 200px;
margin: 0 auto;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
overflow: hidden;
}
.as-main-heading {
color: #fff;
text-transform: uppercase;
font-size: 36px;
font-weight: 300;
}
.as-main-excerpt {
color: #fff;
font-size: 18px;
}
.header-section .first,
.header-section .second,
.header-section .third,
.header-section .fourth {
position: absolute;
left: 0;
right: 0;
animation-duration: 12s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.header-section .first {
animation-name: anim-1;
}
.header-section .second {
animation-name: anim-2;
}
.header-section .third {
animation-name: anim-3;
}
.header-section .fourth {
animation-name: anim-4;
}
@keyframes anim-1 {
0%,
8% {
opacity: 0;
top: 54%;
}
8%,
16% {
bottom: 25%;
top: 54%;
opacity: 1;
}
25%,
100% {
bottom: 50%;
top: 25%;
opacity: 0;
}
}
@keyframes anim-2 {
0%,
25% {
opacity: 0;
}
32%,
40% {
bottom: 25%;
opacity: 1;
}
50%,
100% {
bottom: 50%;
opacity: 0;
}
}
@keyframes anim-3 {
0%,
50% {
opacity: 0;
}
58%,
66% {
bottom: 25%;
opacity: 1;
}
75%,
100% {
bottom: 50%;
opacity: 0;
}
}
@keyframes anim-4 {
0%,
75% {
opacity: 0;
}
81%,
92% {
bottom: 25%;
opacity: 1;
}
100% {
bottom: 50%;
opacity: 0;
}
}<div class="wrapper">
<video autoplay muted loop id="myVideo" height="800px;">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
<div class="landing-header">
<div class="header-section">
<section>
<h2 class="as-main-heading">Story of a bunny</h2>
<div class="as-main-excerpt first">
<p>Here comes a butterfly</p>
</div>
<div class="as-main-excerpt second">
<p>Bunny See's the butterfly</p>
</div>
<div class="as-main-excerpt third">
<p>Butterfly Sitting on the flower</p>
</div>
<div class="as-main-excerpt fourth">
<p>An apple falls on the butterfly</p>
</div>
</section>
</div>
</div>
</div>
发布于 2018-07-23 07:52:36
只要每次视频开始一个新的循环,你就可以很简单地重新启动整个动画。
若要检测此事件,可以侦听媒体事件onplaying。
要重新启动动画,可以在父元素上设置一个类(例如.playing),该类将指示动画何时处于活动状态,然后删除该类和力a,以便浏览器禁用动画,并最终设置播放类。
var header = document.querySelector('.header-section');
myVideo.onplaying = function(e) {
header.classList.remove('playing'); // deactivate the animation
header.offsetWidth; // force a reflow
header.classList.add('playing'); // reactivate the animation
} body {
background-color: #02001b;
}
.wrapper {
position: relative;
width: 1455px;
height: 799px;
margin: 0 auto;
}
.header-section section {
width: 45%;
height: 200px;
margin: 0 auto;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
overflow: hidden;
}
.as-main-heading {
color: #fff;
text-transform: uppercase;
font-size: 36px;
font-weight: 300;
}
.as-main-excerpt {
color: #fff;
font-size: 18px;
}
.header-section .first,
.header-section .second,
.header-section .third,
.header-section .fourth {
position: absolute;
left: 0;
right: 0;
animation-duration: 12s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
/* The animation is set only when the parent has the .playing class */
.header-section.playing .first {
animation-name: anim-1;
}
.header-section.playing .second {
animation-name: anim-2;
}
.header-section.playing .third {
animation-name: anim-3;
}
.header-section.playing .fourth {
animation-name: anim-4;
}
@keyframes anim-1 {
0%,
8% {
opacity: 0;
top: 54%;
}
8%,
16% {
bottom: 25%;
top: 54%;
opacity: 1;
}
25%,
100% {
bottom: 50%;
top: 25%;
opacity: 0;
}
}
@keyframes anim-2 {
0%,
25% {
opacity: 0;
}
32%,
40% {
bottom: 25%;
opacity: 1;
}
50%,
100% {
bottom: 50%;
opacity: 0;
}
}
@keyframes anim-3 {
0%,
50% {
opacity: 0;
}
58%,
66% {
bottom: 25%;
opacity: 1;
}
75%,
100% {
bottom: 50%;
opacity: 0;
}
}
@keyframes anim-4 {
0%,
75% {
opacity: 0;
}
81%,
92% {
bottom: 25%;
opacity: 1;
}
100% {
bottom: 50%;
opacity: 0;
}
}<div class="wrapper">
<video autoplay muted loop id="myVideo" height="800px;">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
<div class="landing-header">
<div class="header-section">
<section>
<h2 class="as-main-heading">Story of a bunny</h2>
<div class="as-main-excerpt first">
<p>Here comes a butterfly</p>
</div>
<div class="as-main-excerpt second">
<p>Bunny See's the butterfly</p>
</div>
<div class="as-main-excerpt third">
<p>Butterfly Sitting on the flower</p>
</div>
<div class="as-main-excerpt fourth">
<p>An apple falls on the butterfly</p>
</div>
</section>
</div>
</div>
</div>
对于更改所有内容(即需要暂停和播放功能)的注释,最好的方法可能是完全消除CSS动画,并控制所有来自js的元素(通过CSS转换提供帮助):
var header = document.querySelector('.header-section');
var chapters = [0, 0.96, 1.92, 2.9, 4.2, 5.4, 6.5, 7.2, 9, 11];
var classes = ['', 'first-in', 'first-out', 'second-in', 'second-out', 'third-in', 'third-out', 'fourth-in', 'fourth-out', ''];
var currentFrame = 0;
myVideo.ontimeupdate = function() {
var nextFrame = (currentFrame + 1) % chapters.length;
if(myVideo.currentTime >= chapters[nextFrame] || myVideo.currentTime < chapters[currentFrame]) {
// if(classes[currentFrame]) header.classList.remove(classes[currentFrame]);
if(classes[nextFrame]) header.classList.add(classes[nextFrame]);
currentFrame = nextFrame;
if(!nextFrame) // did loop
classes.forEach(remove);
header.offsetTop;
}
};
function remove(classname) {
if(classname)header.classList.remove(classname);
}
onclick = function(e) {
if(myVideo.paused) myVideo.play();
else myVideo.pause();
}body {
background-color: #02001b;
}
.wrapper {
position: relative;
width: 1455px;
height: 799px;
margin: 0 auto;
}
.header-section section {
width: 45%;
height: 200px;
margin: 0 auto;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
overflow: hidden;
}
.as-main-heading {
color: #fff;
text-transform: uppercase;
font-size: 36px;
font-weight: 300;
}
.as-main-excerpt {
color: #fff;
font-size: 18px;
}
.header-section .as-main-excerpt {
position: absolute;
left: 0;
right: 0;
opacity: 0;
top: 54%;
transition-property: opacity bottom top;
transition-duration: 1s;
transition-timing-function: ease-in-out;
}
.header-section.first-in .first,
.header-section.second-in .second,
.header-section.third-in .third,
.header-section.fourth-in .fourth {
bottom: 25%;
top: 54%;
opacity: 1;
}
.header-section.first-out .first,
.header-section.second-out .second,
.header-section.third-out .third,
.header-section.fourth-out .fourth {
bottom: 50%;
top: 25%;
opacity: 0;
}
video {
pointer-events: none;
}<div class="wrapper">
<video autoplay muted loop id="myVideo" height="800px;">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
<div class="landing-header">
<div class="header-section playing">
<section>
<h2 class="as-main-heading">Story of a bunny</h2>
<div class="as-main-excerpt first">
<p>Here comes a butterfly</p>
</div>
<div class="as-main-excerpt second">
<p>Bunny See's the butterfly</p>
</div>
<div class="as-main-excerpt third">
<p>Butterfly Sitting on the flower</p>
</div>
<div class="as-main-excerpt fourth">
<p>An apple falls on the butterfly</p>
</div>
</section>
</div>
</div>
</div>
发布于 2018-07-20 09:07:33
您可以使用动画延迟延迟文本动画。
.header-section .first,
.header-section .second,
.header-section .third,
.header-section .fourth {
position: absolute;
left: 0;
right: 0;
animation-duration: 12s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-delay: 1s;
}https://stackoverflow.com/questions/51438747
复制相似问题