Hello there,
I'm having trouble pausing my Timeline. When I add paused:true it still plays the animation. Here is my code :
const _this = this;
this.animationIsPlaying = false;
this.menuActive = false;
// OPEN
const tlOpen = new TimelineMax({
paused: true,
onComplete() {
_this.animationIsPlaying = false;
}
});
tlOpen.fromTo('.menu__bg', 1.2, {
height: '0'
}, {
height: '100%',
ease: Expo.easeInOut,
force3D: true
}).fromTo('.menu__container', 0.6, {
y: 80,
opacity: 0
}, {
y: 0,
opacity: 1,
ease: Power1.easeOut,
}, '-=0.6');
// CLOSE
const tlClose = new TimelineMax({
paused: true,
onComplete() {
_this.animationIsPlaying = false;
TweenLite.set('.menu', {
autoAlpha: 0
});
document.body.classList.remove('menu-active');
}
});
tlClose.fromTo('.menu__container', 0.6, {
y: 0,
opacity: 1
}, {
y: 80,
opacity: 0,
ease: Power1.easeOut,
}).fromTo('.menu__bg', 1.2, {
height: '100%'
}, {
height: '0',
force3D: true,
ease: Expo.easeInOut
}, '-=0.8');
$('.btn-menu').on('click', (e) => {
e.preventDefault();
if (_this.animationIsPlaying) {
return;
}
if (_this.menuActive) {
_this.animationIsPlaying = true;
_this.menuActive = false;
tlClose.play(0);
e.target.classList.remove('active');
} else {
_this.animationIsPlaying = true;
_this.menuActive = true;
TweenLite.set('.menu', {
autoAlpha: 1
});
tlOpen.play(0);
document.body.classList.add('menu-active');
e.target.classList.add('active');
}
});
My solution for the moment is to separate it like this :
openMenu() {
const _this = this;
const tlOpen = new TimelineMax({
onComplete() {
_this.animationIsPlaying = false;
}
});
tlOpen.fromTo('.menu__bg', 1.2, {
height: '0'
}, {
height: '100%',
ease: Expo.easeInOut,
force3D: true
}).fromTo('.menu__container', 0.6, {
y: 80,
opacity: 0
}, {
y: 0,
opacity: 1,
ease: Power1.easeOut,
}, '-=0.6');
}
closeMenu() {
const _this = this;
const tlClose = new TimelineMax({
onComplete() {
_this.animationIsPlaying = false;
TweenLite.set('.menu', {
autoAlpha: 0
});
document.body.classList.remove('menu-active');
}
});
tlClose.fromTo('.menu__container', 0.6, {
y: 0,
opacity: 1
}, {
y: 80,
opacity: 0,
ease: Power1.easeOut,
}).fromTo('.menu__bg', 1.2, {
height: '100%'
}, {
height: '0',
force3D: true,
ease: Expo.easeInOut
}, '-=0.8');
}
menuInit() {
const _this = this;
this.animationIsPlaying = false;
this.menuActive = false;
$('.btn-menu').on('click', (e) => {
e.preventDefault();
if (_this.animationIsPlaying) {
return;
}
if (_this.menuActive) {
_this.animationIsPlaying = true;
_this.menuActive = false;
_this.closeMenu();
e.target.classList.remove('active');
} else {
_this.animationIsPlaying = true;
_this.menuActive = true;
TweenLite.set('.menu', {
autoAlpha: 1
});
_this.openMenu();
document.body.classList.add('menu-active');
e.target.classList.add('active');
}
});
}
Thanks for your help