我一直试图将h2
元素从h1
元素的最终位置放下,使其完全加载并停止其过渡。我无法实现这一目标,目前h2
元素只是从h1
元素的下方淡入。
这是我的code:
$('#header').delay(3250).animate({ 'opacity': [1, "linear"] }, 500);
$('#subheader').delay(4000).animate({ 'opacity': [1, "linear"] }, 500);
h1, h2 {
opacity: 0;
}
/* HEADER TRANSITION */
.moveHeader {
-webkit-animation: headerMoving 1.5s;
animation: headerMoving 1.5s;
animation-fill-mode: forwards;
animation-delay: 3s;
}
@-webkit-keyframes headerMoving {
from {
-webkit-transform: translateY(-30px);
}
to {
-webkit-transform: translateY(0px);
}
}
@keyframes headerMoving {
from {
transform: translateY(-30px);
}
to {
transform: translateY(0px);
}
}
/* SUBHEADER TRANSITION */
.moveSub {
-webkit-animation: subMoving 1s;
animation: subMoving 1s;
animation-fill-mode: forwards;
animation-delay: 4s;
}
@-webkit-keyframes subMoving {
from {
-webkit-transform: translateY(-10px);
}
to {
-webkit-transform: translateY(0px);
}
}
@keyframes subMoving {
from {
transform: translateY(-10px);
}
to {
transform: translateY(0px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1 id="header" class="moveHeader">Header</h1>
<h2 id="subheader" class="moveSub">Subheader</h2>
按run键,动画开始需要3/4秒。
谢谢!
答案 0 :(得分:3)
像这样?您只需要在子标题转换中将translateY
的值从-10
更改为-50
。试一试,看看最适合您的。
尝试一下,看看是否正是您所需要的。
$('#header').delay(3250).animate({ 'opacity': [1, "linear"] }, 500);
$('#subheader').delay(4000).animate({ 'opacity': [1, "linear"] }, 500);
h1, h2 {
opacity: 0;
}
/* HEADER TRANSITION */
.moveHeader {
-webkit-animation: headerMoving 1.5s;
animation: headerMoving 1.5s;
animation-fill-mode: forwards;
animation-delay: 3s;
}
@-webkit-keyframes headerMoving {
from {
-webkit-transform: translateY(-30px);
}
to {
-webkit-transform: translateY(0px);
}
}
@keyframes headerMoving {
from {
transform: translateY(-30px);
}
to {
transform: translateY(0px);
}
}
/* SUBHEADER TRANSITION */
.moveSub {
-webkit-animation: subMoving 1s;
animation: subMoving 1s;
animation-fill-mode: forwards;
animation-delay: 4s;
}
@-webkit-keyframes subMoving {
from {
-webkit-transform: translateY(-50px);
}
to {
-webkit-transform: translateY(0px);
}
}
@keyframes subMoving {
from {
transform: translateY(-50px);
}
to {
transform: translateY(0px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1 id="header" class="moveHeader">Header</h1>
<h2 id="subheader" class="moveSub">Subheader</h2>