简体   繁体   English

GSAP - reverse() 不返回动画

[英]GSAP - reverse() don't animate back

The animation works when it is played but does not work when I use reverse() function animation 在播放时有效,但在我使用 reverse() 时无效 function

It's demo https://codesandbox.io/s/gatsby-express-9uqi7 Navbar component这是演示https://codesandbox.io/s/gatsby-express-9uqi7 导航栏组件

const [state, setState] = useState(false);
    const menuManage = (e)=> {
        if(!e.target.classList.contains('select')){
            const wrapper = document.querySelector('.wrapper');
            const tl = new TimelineMax({paused: true})
                .to(wrapper, 0.15, {height: '100vh', width: '100vw', left:0})
                .to(wrapper, 0.15, {borderBottomLeftRadius: '0%'});
            if(state){
                tl.reverse();
                setState(false);
            }
            else{
                tl.play();
                setState(true);
            }
        }
    }

I'm guessing that this is because the timeline's playhead is at the beginning of the timeline when you're calling .reverse() .我猜这是因为当您调用.reverse()时,时间线的播放头位于时间线的开头。 Try tl.progress(1).reverse();试试tl.progress(1).reverse(); instead.反而。 Without a demo, it's impossible to tell if this is the issue.如果没有演示,就无法判断这是否是问题所在。

I finished my problem in this way我以这种方式完成了我的问题

const [state, setState] = useState(false);
    const menuManage = (e)=> {
        if(!e.target.classList.contains('select')){
            const wrapper = document.querySelector('.wrapper');
            const tl = new TimelineMax({paused: true})
                .to(wrapper, 0.15, {height: '100vh', width: '100vw', left:0})
                .to(wrapper, 0.15, {borderBottomLeftRadius: '0%'});
            if(!wrapper.animation) wrapper.animation = tl;
            state ? wrapper.animation.progress(1).reverse() : wrapper.animation.play();
            setState(!state);
        }
    }

Each time when i click i overwrote timeline in old code.每次单击时,我都会用旧代码覆盖时间线。

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

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