javascript - React js CSS模块找不到@keyframes
问题描述
我正在尝试使用 react css style-inline 为我的 div 设置动画,其目标是仅在相应的 CSS 模块(home.module.css)上使用关键帧旋转,但它不起作用。每个人都知道为什么似乎从未调用过 @keyframes 吗?
仅当我将 @keyframes 放入 global.css 时它才有效
import React from "react"
import classes from "./home.module.css"
export default function Home(){
return (
<div
className={classes.test}
style={{animation: rotation 20s linear infinite}}
>
Rotation test
<div>
)
}
.test {
background-color: #ffff
}
@keyframes rotation {
from {
transform: rotate(0deg);
} to {
transform: rotate(360deg);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
解决方案
您必须在以下位置调用动画效果.test
:
.test {
background-color: #ffff;
animation: rotation 20s linear infinite;
}
@keyframes rotation {
from {
transform: rotate(0deg);
} to {
transform: rotate(360deg);
}
}
而且您不需要添加内联样式:
export default function Home(){
return (
<div className={classes.test} >
Rotation test
<div>
)
}
推荐阅读
- haskell - 带有 lambda 表达式的 Foldl
- class - 无类飞镖文件的目的是什么?
- python - 列表操作的 Python 列表
- unity3d - 从搅拌机导入对象后,Unity 相机卡在构建文件中的特定视图中
- wordpress - 在 https 域上安装了 Wordpress,现在 http 站点不会显示
- amazon-web-services - 从传入的 SES 电子邮件触发事件的最佳方式
- javascript - 尝试放置新项目时出现 DynamoDB InvalidParameterType 错误
- javascript - 我如何在我的反应页面中使用 jquery/html/css 组件
- android - 如何在底部导航中使所选项目可点击
- java - 无法从 Kotlin 中的自定义 ResyclerView 扩展适配器