【问题标题】:how to animate text when it updates using react-spring?使用react-spring更新时如何为文本设置动画?
【发布时间】:2019-07-10 08:38:49
【问题描述】:

在 react.js 应用程序中, 我在 App 状态中存储了一些简单的文本,并传递给将直接显示它的子组件。 我想为过渡设置动画,这样当它发生变化时,以前的文本会淡出,然后传入的文本会淡入。

使用 react-spring 怎么可能?

【问题讨论】:

标签: reactjs animation text transition react-spring


【解决方案1】:

您可以将其放入过渡中,它会为您处理:

const transitions = useTransition(text, null, {
  from: { opacity: 0 },
  enter: { opacity: 1 },
  leave: { opacity: 0 }
})
return transitions.map(({ item, key, props }) => (
  <animated.div style={props}>{item}</animated.div>
))

如果您希望文本短语相互重叠,请确保 div 绝对定位。

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 1970-01-01
    • 2021-01-27
    • 2020-03-24
    • 2023-01-05
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多