css - 在 :hover 和 @keyframes 中为同一个 div 使用变换属性
问题描述
div{
width:100px;
height: 100px;
background-color: red;
animation: anim 1s forwards;
opacity: 0;
}
@keyframes anim{
0%{transform: scale(1.2);opacity:0;}
100%{transform: scale(1);opacity:1;}
}
div:hover{
transform: scale(1.05);
}
<div></div>
我遇到了一些代码和转换属性的问题。
我在 div 上有一个入口动画。但是我的悬停动画不起作用,所以看起来它不起作用,因为我已经在动画中使用了“变换”。
有没有办法让它工作?
解决方案
transform
您可以通过添加transition
到div
的变换来制作动画
/* property name | duration | timing function */
transition: transform 1s ease-in;
在你的情况下
@keyframes anim{
0%{transform: scale(1.2);opacity:0;}
100%{transform: scale(1);opacity:1;}
}
div:hover{
transform: scale(1.05);
}
div{
width:100px;
height: 100px;
background-color: red;
animation: anim 1s;
transition: transform 1s;
}
<div>Hello</div>
推荐阅读
- css - 在离线用户 PC 上加载本地托管字体 (.ttf)(避免跨域请求被阻止)
- vue.js - 如何在不使用 v-model 的情况下检查 Vue.JS 2 中的单选按钮
- python - 根据用户输入或命令行参数选择要在运行时实例化的 Python 类
- antlr - 为 XML 解析添加一些规则
- reactjs - 动态标签宽度文本字段概述材料ui反应
- java - 如何使用 insertColumn(int j, 向量列)
- r - 如何从excel表中提取数据并用闪亮的方式显示?
- android - 从 React Native 中的目录加载一组图像
- java - 如何在 Spring WebClient 中捕获 ConnectionException?
- c# - UML中的Thread等其他类型的属性?