简体   繁体   English

Gatsby、Gsap - 构建后 gsap 动画不起作用

[英]Gatsby, Gsap - gsap animations not working after build

I'm creating website using gatsby and gsap.我正在使用 gatsby 和 gsap 创建网站。 All animations are working while development, but not on production version.所有动画在开发过程中都可以运行,但在生产版本中不能运行。

I'm animating a svg image, using Gsap V3.我正在使用 Gsap V3 为 svg 图像制作动画。

Where could be a problem?哪里可能有问题?

Thanks for feedback!感谢反馈!

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>
  )
}

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM