gpt4 book ai didi

css - 悬停后渐变动画在循环中保持颜色

转载 作者:太空宇宙 更新时间:2023-11-04 07:33:52 25 4
gpt4 key购买 nike

好奇我如何让我的 h1 文本的颜色在悬停并激活彩虹动画后循环保持当前颜色!

h1 {
margin: 0;
font-size: 5em;
color: #00f;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

h1:hover{
-webkit-animation: rainbow 10s infinite;
}

@-webkit-keyframes rainbow{
20%{color: red; left 600ms 3s, top 1.5s 3s;}
40%{color: yellow; left 600ms 3s, top 1.5s 3s;}
60%{color: green; left 600ms 3s, top 1.5s 3s;}
80%{color: orange; left 600ms 3s, top 1.5s 3s;}
100%{color: blue; left 600ms 3s, top 1.5s 3s;}

最佳答案

您可以像这样依赖 animation-play-state 属性:

h1 {
margin: 0;
font-size: 5em;
color: #00f;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
animation: rainbow 10s infinite;
animation-play-state: paused;
}

h1:hover {
animation-play-state: running;
}

@keyframes rainbow {
20% {
color: red;
}
40% {
color: yellow;
}
60% {
color: green;
}
80% {
color: orange;
}
100% {
color: blue;
}
<h1>SOME TEXT</h1>

关于css - 悬停后渐变动画在循环中保持颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49143732/

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