css - 无法使用变换函数制作动画
问题描述
我一直在尝试用几乎所有的变换功能为我的图像设置动画,但没有成功。
谷歌搜索后,似乎设置with: auto
可能是原因。
但是从我的风格中删除它根本不会改变任何东西。还是没有动画。
这里有我的代码:
html,
body {
height: 100%;
}
body {
margin: 0;
}
.logo-container {
display: flex;
height: 100%;
background-color: red;
justify-content: center;
align-items: center;
}
.logo {
width: auto;
transition: scale-me 1.5s ease-in;
animation-iteration-count: infinite;
}
@keyframes scale-me {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="logo-container">
<img src="../images/Green-Monster-8-icon-128.png" class="logo" />
</div>
</body>
我的代码有什么问题?
提前致谢。
解决方案
你必须使用animation
而不是transition
html,
body {
height: 100%;
}
body {
margin: 0;
}
.logo-container {
display: flex;
height: 100%;
background-color: red;
justify-content: center;
align-items: center;
}
.logo {
width: auto;
animation: scale-me 1.5s ease-in;
animation-iteration-count: infinite;
}
@keyframes scale-me {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="logo-container">
<img src="https://via.placeholder.com/50" class="logo" />
</div>
</body>
推荐阅读
- python - 我开始,我想知道这个简单的代码不起作用(更准确地说是方法攻击播放器)?
- azure - 即使在 versionType 设置为 latest 之后,Azure DownloadGitHubRelease@0 也在寻找版本标记
- spring-batch - com.atomikos.jdbc.AtomikosSQLException:连接池已用尽 - 尝试增加“maxPoolSize”和/或“borrowConnectionTimeout”
- windows - 如何使用 findstr 提取文件中的某些文本
- visual-studio-code - 如何将代码行绑定到 VSCode 中的值?
- r - 使用负值和正值更改条数(ggplot)的位置
- android - 在 Browserstack 上自动运行测试时,apk 和 espresso apk 之间的签名不匹配
- css - WordPress 移动菜单
- reporting-services - SSRS 钻取报表使用表达式报表名称无效
- python - NGINX 110:在配置最大文件大小后从上游读取响应标头时连接超时