N
N
Nikita Ivanov2016-11-16 19:08:26
JavaScript
Nikita Ivanov, 2016-11-16 19:08:26

How to add/remove class at start and end of tweenmax animation?

How can I add the class as the animation started and remove the class when it ended.

var tl = new TimelineLite();
tl.from('#heroPreloader', 2, {onStart: onStart, onComplete: onComplete})
.from('#heroContent', 3, {autoAlpha: 0});

function onStart() {
  tl.set('#heroPreloader', {className: '+=preloader_show'});
}

function onComplete() {
  tl.set('#heroPreloader', {className: '-=preloader_show'})
}

For some reason, in the onStart and onComplete callbacks, the class is not added and removed at the start of the animation and the end of the animation. Although console.log is normally called from these functions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Evgrafovich, 2016-11-16
@Tantacula

The documentation says that the first argument to set() should be an object, not a string. Replace with $('#heroPreloader')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question