首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用styled-components - React传递道具到关键帧

使用styled-components - React传递道具到关键帧
EN

Stack Overflow用户
提问于 2021-08-12 01:39:00
回答 1查看 45关注 0票数 0

我不能将'inicial‘和'final’作为道具传递给关键帧。你能帮帮我吗?

代码语言:javascript
复制
const sliderzada = keyframes`
 from {
  transform: translate(${0}px) //i need 'inicial' here
 }
 to {
  transform: translate(${-1250}px) //i need 'final' here
 }
`;

const animation = css`
animation: ${ sliderzada} 1.2s ease-in-out;
`;

const Sliderzin = styled.div`
${props => props.isClicked && animation}
`;

const Slider = () => {

const [isClicked, setIsClicked] = React.useState(false)
const [inicial, setInicial] = React.useState(0)
const [final, setFinal] = React.useState(-1250)

return (
    <div className={styles.wrapper}>
        <Sliderzin inicial={inicial} final={final} isClicked={isClicked}>
        </Sliderzin>
    </div>
)

}

我只需要在关键帧中使用'inicial‘和'final’。

EN

回答 1

Stack Overflow用户

发布于 2021-08-12 02:13:10

您只需像这样添加props

代码语言:javascript
复制
const sliderzada = (props) => keyframes`
  from {
    transform: translate(${props.inicial}px) //i need 'inicial' here
  }
  to {
    transform: translate(${props.final}px) //i need 'final' here
  }
`;


const animation = (props) => css`
  animation: ${sliderzada(props)} 1.2s ease-in-out;
`;

const Sliderzin = styled.div`
  ${props => props.isClicked && animation(props)}
`;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68750631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档