简体   繁体   English

React:如何将 css 过渡添加到内联样式

[英]React: how to add css transition into inline style

I would like to have a button, after clicked, state isBackward become true and the inline-style would be added into the div container and have animation.我想要一个按钮,单击后,state isBackward 变为 true,并且内联样式将添加到 div 容器中并具有 animation。

I have tried below code in React, only transition doesn't work, other properties work.我在 React 中尝试过下面的代码,只有转换不起作用,其他属性起作用。 Anyone got the idea to have the transition for the marginLeft to have animation?有没有人想到让 marginLeft 过渡到 animation?

const slideStyle = {
    width: 400 + "%",
    marginLeft: dis + "px",
    transition: "marginLeft 1s"
  };

 <div style={isBackward ? slideStyle : null} className="quote-box-wrap">
     {quotes.map((item, index) => (
          <Quote
            key={index}
            id={index}
            content={item.sentence}
            author={item.author}
          />
     ))}
</div>

I think you must write as follows:我认为你必须写如下:

  const slideStyle = {
    width: 400 + "%",
    marginLeft: dis + "px",
    transition: "margin-left 1s"
  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM