我有以下功能。我将该函数构建为promise. 现在,如果我aboutMove().then(() => {..})第一次打电话,一切正常并且正在解决。不知何故,稍后在其他地方第二次调用它,该函数将被执行,但未promise解析。为何如此?
export const aboutMove = () => {
return new Promise(resolve => {
if (didAboutMove && aboutAnimation) {
aboutAnimation.reverse();
didAboutMove = !didAboutMove;
return;
}
didAboutMove = !didAboutMove;
const about = document.querySelector('.about__container');
const inner = document.querySelector('.about__inner');
aboutAnimation = gsap.timeline({
onComplete: () => {
resolve()
}, onReverseComplete: () => {
resolve()
}
})
.to(about, 1, {
duration: 1,
y: 0,
ease: Power2.easeInOut,
})
.fromTo(inner, {
opacity: 0,
y: 500
}, {
duration: 0.8,
opacity: 1,
y: 0,
ease: Power2.easeInOut
}, 0.5)
});
};
翻过高山走不出你
呼啦一阵风
神不在的星期二
相关分类