Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 盖茨比,Gsap-生成后Gsap动画不工作_Javascript_Reactjs_Gatsby_Gsap - Fatal编程技术网

Javascript 盖茨比,Gsap-生成后Gsap动画不工作

Javascript 盖茨比,Gsap-生成后Gsap动画不工作,javascript,reactjs,gatsby,gsap,Javascript,Reactjs,Gatsby,Gsap,我正在使用盖茨比和gsap创建网站。 所有动画都是在开发时工作的,但不是在生产版本上 我正在使用GSAPv3制作svg图像的动画 哪里会有问题 感谢您的反馈 const HeaderComponent = () => { const animWrapper = useRef(null) useEffect(() => { const [elements] = animWrapper.current.children const what = eleme

我正在使用盖茨比和gsap创建网站。 所有动画都是在开发时工作的,但不是在生产版本上

我正在使用GSAPv3制作svg图像的动画

哪里会有问题

感谢您的反馈

const HeaderComponent = () => {

  const animWrapper = useRef(null)

  useEffect(() => {

    const [elements] = animWrapper.current.children

    const what = elements.getElementById('What')
    const ever = elements.getElementById('Ever')
    const button = document.getElementById('header-button')
    const icon = document.getElementById('header-icon')

    const whatChildrens = what.children
    const everChildrens = ever.children
    const allChildrens = [...whatChildrens, ...everChildrens]

    gsap.set([...allChildrens, button], { autoAlpha: 0 })

    const timeLine = gsap.timeline({ defaults: { ease: 'power3.inOut' } })

    timeLine
      .to(whatChildrens, { autoAlpha: 1, duration: 0.75 })
      .to(everChildrens, { autoAlpha: 1, stagger: 0.025 })
      .to(button, { autoAlpha: 1 })
  }, [])

  return (
      <HeaderWrapper className="header" id="main-header">
        <div ref={animWrapper} id="header-logo-wrapper">
          <WhatEver style={{width: '100%'}}/>

          <HeaderButton id="header-button" onClick={() => scrollTo('#poznaj-nas')}>
            <FontAwesomeIcon icon={faArrowDown} id="header-icon"/>
          </HeaderButton>
        </div>
      </HeaderWrapper>
  )
}
const HeaderComponent=()=>{
常量animWrapper=useRef(null)
useffect(()=>{
常量[元素]=animWrapper.current.children
const what=elements.getElementById('what')
const ever=elements.getElementById('ever'))
const button=document.getElementById('header-button'))
const icon=document.getElementById('header-icon'))
const whatChildrens=what.children
const everChildrens=ever.childrens
const allChildrens=[…什么孩子,…每个孩子]
gsap.set([…所有儿童,按钮],{autoAlpha:0})
const timeLine=gsap.timeLine({默认值:{ease:'power3.inOut'}})
时间线
.to(whatchildren,{autoAlpha:1,duration:0.75})
.to(everChildrens,{autoAlpha:1,stagger:0.025})
.to(按钮,{autoAlpha:1})
}, [])
返回(
滚动到('poznaj nas')}>
)
}

您需要导入您使用的内容,例如:

import { gsap, TweenMax, TimelineMax, Power2 } from "gsap/dist/gsap";

您是否有社区可以帮助您的代码片段?谢谢@是的,这是我的仓库。动画位于标题组件中。github.com/Zeberko200/whatever-gatsbyLinking到一个存储库使得这个问题在将来对其他人没有用处。这个问题应该尽可能的独立,这样在你得到答案后,它对其他人来说仍然有用。请在CodeSandbox或StackBlitz项目中重新创建这个问题。不,我使用的是盖茨比V3,而不是V2:)@Zachsauier谢谢你的有用回答。我的答案基于github上提供的一个类似问题的答案。Lukas看一看:没有理由在GSAP3中从GSAP加载TweenMax、TimelineMax或Power2,除非用户只是希望东西向后兼容。OP没有使用任何需要这些导入的GSAP 2格式