gpt4 book ai didi

javascript - 停止页面加载时自动启动的关键帧动画

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:44 24 4
gpt4 key购买 nike

我有一些用于运行几个 Div 元素的 css 和关键帧动画。我希望 css 和关键帧动画仅在我单击我的按钮时启动。我的问题是,它们自己开始,然后动画延迟用完并使按钮无用。

这是我正在尝试的代码。

$(document).ready(function(){
$("#bt1").click(function(){
$(".animation-box").addClass("first-text", "second-text", "third-text", "fourth-text", "fifth-text");
});


$('.animation-box').on("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function(){
$(this).removeClass("first-text", "second-text", "third-text", "fourth-text", "fifth-text");
});
});
            @keyframes topFadeOut {
0% {
position: absolute;
top: 10%;
opacity: 0;
}

75% {
position: absolute;
top: 50%;
opacity: 1;
}

100% {
opacity: 0;
}
}

@keyframes bottomFadeOut {
0% {
position: absolute;

opacity: 0;
}

75% {
position: absolute;

opacity: 1;
}

100% {
opacity: 0;
}

}

@keyframes topFadeOutVertical {
0% {
position: absolute;
top: 60%;
opacity: 0;

}

75% {
position: absolute;
top: 65%;
opacity: 1;

}

100% {
opacity: 0;

}
}

@keyframes rightFadeInOut {
0% {
position: absolute;
right: -3rem;
opacity: 0;

}

75% {
position: absolute;
right: 40%;
opacity: 1;

}

100% {
opacity: 0;
right: 10rem;

}
}

@keyframes fadeInOut {
0% {
opacity: 0;

}

45% {
opacity: 1;

}

100% {
opacity: 0%;

}
}

.first-text {
font-size: 4.4rem;
position: absolute;
left: 23%;
top: 70%;
opacity: 0;
animation-name: topFadeOut;
animation-duration: 5s;
color: black;
animation-play-state: i;
}

.second-text {
font-size: 4.4rem;
position: absolute;
top: 50%;
opacity: 0;
animation-name: rightFadeInOut;
animation-delay: 4s;
animation-duration: 6s;
color: black;
animation-play-state: inherit;
}

.third-text {

font-size: 4.4rem;
position: absolute;
left: 27%;
top: 50%;
opacity: 0;
animation-name: topFadeOutVertical;
animation-delay: 8s;
animation-duration: 6s;
color: black;
white-space: nowrap;
animation-play-state: inherit;
}

.fourth-text {
font-size: 4.4rem;
position: absolute;
top: 55%;
left: 27%;
opacity: 0;
color: black;
animation-name: fadeInOut;
animation-delay: 12s;
animation-duration: 7s;
animation-play-state: inherit;
}

.fifth-text {
font-size: 5rem;
position: absolute;
left: 30%;
top: 50%;
opacity: 0;
color: black;
animation-name: bottomFadeOut;
animation-delay: 16s;
animation-duration: 9s;
animation-play-state: inherit;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="bt1" class="button button5">< R30K</button>
<button id="bt2" class="button button5">R30K - R70K</button>
<button id="bt3" class="button button5">> R70K</button>

<section class="animation-box">
<div class="first-text">Starting winner selection process</div>
<div class="second-text">Identifying eligible entries</div>
<div class="third-text">Uploading eligible entries</div>
<div class="fourth-text">Shuffling eligible entries</div>
<div class="fifth-text">And the winner is...</div>
</section>

所以当运行它时,关键帧动画在页面加载时开始,导致我无法使用按钮功能。

我想知道如何在页面加载时停止关键帧启动以及仅在单击按钮时运行关键帧。

非常感谢您的帮助。

最佳答案

使用animation-play-state 属性将动画设置为初始暂停

https://developer.mozilla.org/en-US/docs/Web/CSS/animation-play-state

关于javascript - 停止页面加载时自动启动的关键帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56193172/

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