Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
oligsap

TimelineMax fires even with paused: true

Recommended Posts

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

Link to post
Share on other sites
2 hours ago, oligsap said:

When I add paused:true it still plays the animation.

There's nothing that jumps out at me as being incorrect. Could you please create a minimal demo so that we can see the issue firsthand? 

 

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×