Javascript GSAP-reverse()don';不要使背部生动活泼

Javascript GSAP-reverse()don';不要使背部生动活泼,javascript,reactjs,gsap,Javascript,Reactjs,Gsap,动画在播放时起作用,但在使用reverse()函数时不起作用 这是演示导航栏组件 const[state,setState]=useState(false); 常数menuManage=(e)=>{ 如果(!e.target.classList.contains('select')){ const wrapper=document.querySelector('.wrapper'); const tl=new TimelineMax({暂停:true}) .to(包装,0.15,{高度:“100

动画在播放时起作用,但在使用reverse()函数时不起作用

这是演示导航栏组件

const[state,setState]=useState(false);
常数menuManage=(e)=>{
如果(!e.target.classList.contains('select')){
const wrapper=document.querySelector('.wrapper');
const tl=new TimelineMax({暂停:true})
.to(包装,0.15,{高度:“100vh”,宽度:“100vw”,左侧:0})
.to(包装,0.15,{borderBottomLeftRadius:'0%});
如果(州){
tl.反向();
设置状态(假);
}
否则{
tl.play();
设置状态(真);
}
}
}

我猜这是因为当您调用
.reverse()
时,时间线的播放头位于时间线的开头。尝试
tl.progress(1.reverse()取而代之。如果没有演示,就无法判断这是否是问题所在。

我就是这样解决问题的

const[state,setState]=useState(false);
常数menuManage=(e)=>{
如果(!e.target.classList.contains('select')){
const wrapper=document.querySelector('.wrapper');
const tl=new TimelineMax({暂停:true})
.to(包装,0.15,{高度:“100vh”,宽度:“100vw”,左侧:0})
.to(包装,0.15,{borderBottomLeftRadius:'0%});
如果(!wrapper.animation)wrapper.animation=tl;
状态?wrapper.animation.progress(1.reverse():wrapper.animation.play();
设置状态(!状态);
}
}

每次单击时,我都会用旧代码重写时间线。

GSAP最近发布了v。3@TedFitzpatrick这与这个家伙的解决方案有点无关。我会尽快尝试它。工作:/这是演示