【问题标题】:React spring loop won't run with delay反应弹簧循环不会延迟运行
【发布时间】:2022-01-20 21:25:20
【问题描述】:

我在react spring中使用这些样式,运行一次后就不再运行了,如果我去掉延迟就可以正常运行,这是为什么呢?

const styles = useSpring({
  loop: true,
  to: [
    { opacity: 0, color: '#53317e' },
    { opacity: 1, color: 'white' },
  ],
  from: { opacity: 1, color: 'white' },
  delay: 1000,
})

【问题讨论】:

    标签: react-spring


    【解决方案1】:

    很多时间过去了,但我遇到了同样的问题。

    修复它,而不是使用

    const styles = useSpring({ 
       loop: true,
       delay: 2000,
       from: {...},
       to: [{...}, {...}, ...]
     });
    

    我使用传递函数而不是对象的语法

      const [styles, api] = useSpring(() => ({ ... }) )
    

    然后延迟道具停止禁用我的循环

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2019-06-07
      • 2016-08-18
      • 1970-01-01
      相关资源
      最近更新 更多