css - 悬停后如何使动画保持在最后一个关键帧?
问题描述
我试图让一个褪色的段落在悬停时变得 100% 可见,然后即使在用户不再将鼠标悬停在文本上之后也保持不变。
这是我的代码:
#p30 {
font-family: Frijole;
opacity: .1;
font-size: 36px;
top: 7141px;
left: 365px;
}
#p30:hover {
animation: fade 2.3s;
animation-timing-function: linear;
animation-fill-mode: forwards;
animation-iteration-count: 1;
}
@keyframes fade {
from {opacity: .1;}
to {opacity: 1;}
}
解决方案
使用过渡并考虑一个很大的时间来伪造它
.box {
font-family: Frijole;
opacity: .1;
font-size: 36px;
transition:999s opacity;
}
.box:hover {
transition:1s opacity;
opacity:1;
}
<div class="box">text here</div>
如果你想继续使用动画的另一个想法
.box {
font-family: Frijole;
opacity: .1;
font-size: 36px;
animation: fade 1s forwards;
animation-play-state: paused;
}
.box:hover {
animation-play-state: running;
}
@keyframes fade {
from {opacity: .1;}
to {opacity: 1;}
}
<div class="box">text here</div>
推荐阅读
- c# - 将表加入实体框架中的列表
- python - 为什么我的 Django 应用程序无法读取环境变量集?
- python - 比较合并表中的多个列时出现 TypeError
- python - 如何让 demand_callback 考虑依赖于 ortools 中 to_node 的变量?
- android - 反应本机颜色问题
- parameters - 有没有办法将 Quicksight 电子邮件报告更新到今天的日期?
- python - 使用 pytracking 在 Python 中获取 1x1 透明 PNG 像素的问题
- php - 使用 php 为 Emma API 引入可选参数
- python - 代码随机不遵循 For Loop 的指令
- python - Pandas 均值数据透视表包含 NaN 值,即使在聚合之前填充了数据