Jump to content
Search Community

Loading HTML with AJAX and killing tweens

willarends test
Moderator Tag

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 have built a single page app using jQuery .load() to read the url and fetch the according html snipped which contains the SVG's (which are pretty large).

 

function loadPage(page){
    var pageString = `./views/${page}.html`;
    $('#content').fadeOut('normal', function() {
        $(this).load(pageString, (res, status, xhr) => {
            $(this).fadeIn('normal', () => {
                if(page === 'self-service'){
                    selfService.init();
                } else {
                    publicSafety.init();
                }
            });
        });
    });
}

 

Once the html has been loaded onto the page I am calling a init() function which starts my MainTimeline for each page.  

function init() {
        console.log('self service init');


        MainTL
            .add(IconIntro(), 'intro-icon')
            .add(DataFlow(), 'intro-icon+=4')
    }

 

Here I have added a couple timelines to MainTimeline.  When I am leaving the page I kill() all the active timelines so they are no longer playing with a killTL() function.  

 

function killTL(){
        MainTL.kill();
        var timelines = [iconIntroTL, dataFlowTL];
        for (var i = 0; i < timelines.length; i++) {
            clearProps(timelines[i]);
        }
    }

 

The pages load very quickly on first load, but the problem arises when switching back to a page that has already been loaded once.  There is a long delay between the loading of the html/init function and then the playing of the animation.  

 

The demo is scaled back quite a bit, but there are more pages and timelines that are being added and the delay is about 5 seconds each time.  I cannot figure out whats going on as I have tried many combinations of .pause(), restart(), kill() ect..  Is greensock just taking along time to parse the html that was loaded from a ajax call? 

 

Thanks for any help and the project is attached.  

 

//"npm install" and "gulp" 

 

 

 

 

ajax-greensock.zip

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...