Jump to content
GreenSock

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

callback function not working?

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I want to run a function after the end of my animation but the callback function doesn't seem to be working?

 

these are my code:

 

$("body,html").animate({scrollTop: $(".slide2").offset().top}, {duration:2000, easing:"Back.easeInOut"})
.delay(2000).animate({scrollTop: $(".slide3").offset().top}, {duration:2000, easing:"Back.easeInOut"})
.delay(2000).animate({scrollTop: $(".slide4").offset().top}, {duration:2000, easing:"Power4.easeInOut"})
.delay(2000).animate({scrollTop: $("#mainContainer").offset().top}, {duration:2000, ease:"Power2.easeInOut", onComplete:completeHandler });
 
function completeHandler(){
    $(".slide1").unmousewheel();
   alert(callback);
   console.log("callback");
}
Link to comment
Share on other sites

Hi,

 

In the case of GSAP's JQuery plugin the callback is complete, not onComplete, so your code should be like this:

.delay(2000).animate({scrollTop: $("#mainContainer").offset().top}, {duration:2000, ease:"Power2.easeInOut", complete:completeHandler });
 
function completeHandler(){
    $(".slide1").unmousewheel();
   alert(callback);
   console.log("callback");
}

Also let me encourage you once more to use the engine's scrollTo plugin. For example your code would be like this:

var tl = new TimelineMax({onComplete:completeHandler});

tl
    .to(window, 2, {scrollTo:$(".slide2").offset().top, ease:Back.easeInOut})
    .to(window, 2, {scrollTo:$(".slide3").offset().top, ease:Back.easeInOut})
    .to(window, 2, {scrollTo:$(".slide4").offset().top, ease:Power4.easeInOut})
    .to(window, 2, {scrollTo:$("#mainContainer").offset().top, ease:power2.easeInOut});

function completeHandler()
{
    $(".slide1").unmousewheel();
    alert(callback);
    console.log("callback");
}

As you can see is far less code, you can chain into the timeline and the engine takes care of the entire sequence, no need to worry about delays and stuff. Give it a shot and if more questions come up there'll always be an answer.

 

Hope this helps,

Cheers,

Rodrigo.

  • Like 1
Link to comment
Share on other sites

Hi,

 

In the case of GSAP's JQuery plugin the callback is complete, not onComplete, so your code should be like this:

.delay(2000).animate({scrollTop: $("#mainContainer").offset().top}, {duration:2000, ease:"Power2.easeInOut", complete:completeHandler });
 
function completeHandler(){
    $(".slide1").unmousewheel();
   alert(callback);
   console.log("callback");
}

Also let me encourage you once more to use the engine's scrollTo plugin. For example your code would be like this:

var tl = new TimelineMax({onComplete:completeHandler});

tl
    .to(window, 2, {scrollTo:$(".slide2").offset().top, ease:Back.easeInOut})
    .to(window, 2, {scrollTo:$(".slide3").offset().top, ease:Back.easeInOut})
    .to(window, 2, {scrollTo:$(".slide4").offset().top, ease:Power4.easeInOut})
    .to(window, 2, {scrollTo:$("#mainContainer").offset().top, ease:power2.easeInOut});

function completeHandler()
{
    $(".slide1").unmousewheel();
    alert(callback);
    console.log("callback");
}

As you can see is far less code, you can chain into the timeline and the engine takes care of the entire sequence, no need to worry about delays and stuff. Give it a shot and if more questions come up there'll always be an answer.

 

Hope this helps,

Cheers,

Rodrigo.

Thanks Rhernando, I got the callback function working.

 

Yes I'm using the scrollTo plugin now.

I'm posting this because I can't seem to get it working in GSAP's Jquery version but the scrollTo plugin works just fine. 

 

just curious though :-P

Link to comment
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.

×