Jump to content
Search Community

onComplete not work correctly or i dumb?

108saimon test
Moderator Tag

Go to solution Solved by 108saimon,

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

Hi, Everyone!

I faced some problem in my code. Maybe i just not understand GSAP api.

I have code like :

    $('a').click(function(e){
        
        event.preventDefault();
        
        var thishref = this.getAttribute('href');

        //code down for some animation before redirect, in this example very simple

        TweenMax.to('body', 0 ,  {display: 'none', delay: 1, onComplete : href_redirect(thishref) });
        
        });
    
    function href_redirect(t_href) {
        document.location.href=t_href;
    }

in theory sequencing be like : click to link > my animation start > my animation end > redirect .

but in real - instant redirects, without waiting animation end.

in now i forced use code like : 

    $('a').click(function(e){
        
        event.preventDefault();
        
        var thishref = this.getAttribute('href');
        
        TweenMax.to('body', 0 ,  {display: 'none', delay: 1, onComplete : href_redirect(thishref) });
        
        });
    
    function href_redirect(t_href) {
        setTimeout(function(){document.location.href=t_href;},3000); // delay manually
    }

Someone please answer me - what i doing wrong in first example. 

Link to comment
Share on other sites

  • Solution

Sorry, a find answer.

Need use some like :

 

$('a').click(function(e){
        
        event.preventDefault();
        
        var thishref = this.getAttribute('href'); 
        
        TweenMax.to('body', 1 ,  {opacity: 0, onComplete : href_redirect, onCompleteParams:[thishref] }); // use onCompleate + onCompleteParams 
        
        });
    
    function href_redirect(t_href) {
        document.location.href=t_href;
    }
  • Like 1
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.
×
×
  • Create New...