Jump to content
GreenSock

Susan

Not Animating

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

As you are using jQuery,
 

$(document).ready(function(){

TweenMax.to(".logo", 2, {left:600});

});

 

It runs when DOM is ready. Without it, code does execute but as there is no DOM to work with nothing animates.

  • Like 1
Link to comment
Share on other sites

I am very sorry, my Javascript knowledge is shallow.

 

Do you mean to replace this code

 

TweenMax.to(".logo", 2, {left:600});

 

to 

$(document).ready(function(){
TweenMax.to(".logo", 2, {left:600});
});

 

in the main.js file?

 

I have done the replacement but it is still not working.

 

Please assist further, apology for my ignorance, thanks.

Link to comment
Share on other sites

Ya looks like you aren't using jQuery.

 

You can instead use following equivalent in plain JavaScript

 

document.addEventListener("DOMContentLoaded", function(event) { 
  TweenMax.to(".logo", 2, {left:600});
});
Link to comment
Share on other sites

Sorry for the confusion, to animate left and top properties. You need to set position of that element using CSS. If you add following CSS, it will work

 

.logo{
	position: relative;
}

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Hello @Susan and Welcome to the GreenSock Forum!

 

Just to add to @Sahil's great advice.

 

Using his code i would make one small change. convert left to x (translateX). This way you are using CSS transforms which can animate smoother versus CSS position offsets that can trigger layout on each render tick.

 

//wait until DOM is ready
document.addEventListener("DOMContentLoaded", function(event) {  
  
  // wait until window is loaded - all images, links, css, scripts, fonts, and other media assets
  window.addEventListener("load", function(){ 
      
       // run animation code here
       TweenMax.to(".logo", 2, {x:600});
    
  });
});

 

More info on why this better found here:

The window load event makes sure that your logo which i presume is an image is only animated when the DOM is ready (HTML markup), and the window is loaded.  Meaning only run your code to animate the image when both DOM and window is loaded so your animation fires consistently cross browser.

 

Happy Tweening! :)

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

@Jonathan Thank you so much for your kind advice! I really appreciate it, thank you!

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