【问题标题】:How to make a looping animation with react-spring useChain如何使用 react-spring useChain 制作循环动画
【发布时间】:2021-12-31 09:56:33
【问题描述】:

我想用 react-spring 创建一个循环动画来加载,但是当我使用循环时,它的时间错误,我不知道如何制作 useChain 动画循环。

const animation = {
  from: { scale: 0, opacity: 0, background: 'red' },
  to: [
    { scale: 1, opacity: 1 },
    { scale: 0, opacity: 0 }
  ],
  config: {
    duration: 500
  }
}

const Loading = () => {
  const leftBottomRef = useSpringRef()
  const leftBottom = useSpring({
    ref: leftBottomRef,
    ...animation
  })

  const leftTwoRef = useSpringRef()
  const leftTwo = useSpring({
    ref: leftTwoRef,
    ...animation
  })

  const centerRef = useSpringRef()
  const center = useSpring({
    ref: centerRef,
    ...animation
  })

  const rightTwoRef = useSpringRef()
  const rightTwo = useSpring({
    ref: rightTwoRef,
    ...animation
  })

  const rightTopRef = useSpringRef()
  const rightTop = useSpring({
    ref: rightTopRef,
    ...animation
  })

  useChain(
    [leftBottomRef, leftTwoRef, centerRef, rightTwoRef, rightTopRef],
    [0, 0.3, 0.6, 0.9, 1.2],

  )

  return (
    <div className='loading'>
      <div className='loader'>
        <animated.div style={center} />
        <animated.div style={rightTwo} />
        <animated.div style={rightTop} />
        <animated.div style={leftTwo} />
        <animated.div style={center} />
        <animated.div style={rightTwo} />
        <animated.div style={leftBottom} />
        <animated.div style={leftTwo} />
        <animated.div style={center} />
      </div>
      loading...
    </div>
  )
}

如果有办法让useChain循环或者有其他方法来实现这个动画?

这里是我正在尝试做的一些背景

【问题讨论】:

    标签: reactjs react-spring


    【解决方案1】:

    您是否尝试将loop: true 添加到您的animation 对象或其中的config,就像他们拥有in the docs 一样?

    【讨论】:

    • 是的,我确实使用过它,但过了一段时间,时间错了,动画出现故障
    猜你喜欢
    • 2020-07-28
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 2020-01-27
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    相关资源
    最近更新 更多