gpt4 book ai didi

jquery - 文本过渡到重叠

转载 作者:行者123 更新时间:2023-11-28 08:39:22 25 4
gpt4 key购买 nike

我一直在尝试让 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>

按下运行时,动画需要 3/4 秒才能开始。

谢谢!

最佳答案

是这样的吗?您只需要在子标题转换时将 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>

关于jquery - 文本过渡到重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55039910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com