javascript - 使用关键帧动画中的道具的样式化组件
问题描述
在动画中使用道具的正确方法是什么:${styledKeyFrame} ${props.myProps}?
问题:
import styled from 'styled-components';
const KeyFrameTest = styled.keyframes`
from { opacity: 0; }
to { opacity: 1; }
`;
const StyledComponent = styled.div`
animation: ${KeyFrameTest} 2s 4s ease-in; /* works */
animation: ${props => `${KeyFrameTest} 2s ${props.delay} ease-in`}; /* ERROR */
animation: ${props => `${styled.css`{KeyFrameTest}}` 2s ${props.delay} ease-in`}; /* ERROR */
`;
const PureComponent = () => <StyledComponent delay="3s" />;
export default PureComponent;
解决方案
我认为当您尝试在${props => }
语法中使用 KeyFrames 时会发生错误。
我不知道您使用的是哪个版本的样式组件,但我认为这应该可以;
animation: ${KeyFrameTest} 2s ${props => props.delay} ease-in
推荐阅读
- pytorch - 在 PyTorch 中为 nn.functional.conv2d 提供权重
- html - 如何在没有边距的 HTML 表格中的两个文本块之间放置一条线?
- flutter - Flutter web - ReordorableListView,在字段之间悬停时带有+按钮
- html - 媒体查询不起作用。我究竟做错了什么?
- python - pip 命令未找到,安装 django 时在 mac 上未找到 virtualenv 命令
- laravel - 如何在由 Laravel api 提供支持的移动应用程序中处理异地支付
- tomcat - javax.servlet.ServletException:类 [org.glassfish.jersey.servlet.ServletContainer] 不是 Servlet
- java - 如何在硒中并行运行多个类
- javascript - 如何在画布上的多点模式下使用单独的颜色为 D3-Geo 路径点着色
- javascript - 将“require”与 esm 一起使用 - ReferenceError:require 未定义