【问题标题】:React: how to add css transition into inline styleReact:如何将 css 过渡添加到内联样式中
【发布时间】:2020-11-18 13:52:19
【问题描述】:

我想要一个按钮,点击后,isBackward状态变为true,并且内联样式会被添加到div容器中并有动画。

我在 React 中尝试了以下代码,只有转换不起作用,其他属性起作用。 有没有人想到让 marginLeft 有动画的过渡?

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>

【问题讨论】:

    标签: javascript html css reactjs


    【解决方案1】:

    我认为你必须写如下:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-16
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      相关资源
      最近更新 更多