Jump to content

Nisha Prasad

Gsap animations not working in angular when ng build --prod

Recommended Posts

I have been working on angular project and implemented gsap animations. It is working fine when is on local. But when we execute ng build --prod for deployment on server its not working. On server gsap animations are not working. Any idea plz help urgently. Thank You !!!

Link to comment
Share on other sites

Hi Nisha - It's near impossible for us to help without more information I'm afraid.

What exactly is broken? What errors are coming up? What's the difference between your local environment and this production server? Any more information you have would be very useful.

Link to comment
Share on other sites

Here is my home page ts file animation function code


// define images
const images1 = [
const obj1 = {curImg: 0};
trigger: ".page",
toggleActions:"restart pause reverse pause",
start:"top top",
end: "+=140%",
immediateRender: true,
ease: "power2",
curImg: images1.length - 1, // animate propery curImg to number of images
roundProps: "curImg", // only integers so it can be used as an array index
onUpdate: function () {
// set the image source
//$("#fallingBox1").attr("src", images1[obj1.curImg]);
if (document.querySelector("#fallingBox1")){
gsap.set("#fallingBox1", {
attr: { src: images1[obj1.curImg]} ,
duration : 2,
css:{transition:"all 2s ease"},
Link to comment
Share on other sites

The above code is working fine in local but not after ng build --prod

Link to comment
Share on other sites

I'm afraid we need more information Nisha.


Here are some questions.

What isn't working?

Can you explain how it's broken - Is it visually broken or Is the build failing?
Do you have any console errors or build errors?
What is the difference between your production environment and local? 

Any more information you can give us would be very helpful. At the moment there is nothing we can do to advise. This code snippet looks ok, but we have no additional context.

  • Like 2
Link to comment
Share on other sites


The problem is the banner box should smoothly come down as user scroll page down. But the Scroll Trigger is not working.


When we do command ng serve on local its work fine.

But when we do command ng build --prod for putting files on our server.  The ScrollTrigger.create() not working.

Link to comment
Share on other sites

Ok, so a visual issue. Great that's a little further forward, thanks.

Now, I don't know what the banner box is - I also don't know what you mean by smoothly come down. I have no understanding of your project. Can you please explain this to me in simple steps?


Let's start by creating a working demo so I can see what it's meant to look like. Here's a starting point.

See the Pen PoQJojW?editors=1010 by GreenSock (@GreenSock) on CodePen

Optionally some debugging steps -

  • Try adding markers:true to your scrollTrigger to see whether they're in the right place
  • Log out the element you're targeting to see whether it's loaded,
  • Do a console log in the callback and see whether that's firing and updating the right property
  • Log out ScrollTrigger and see whether it's available.


Link to comment
Share on other sites

Yeah, it's super difficult to troubleshoot a live site. The problem could be CSS, a third party JavaScript library, markup, or any number of things. That's why we strongly recommend isolating the issue in a minimal demo. The fact that it works fine locally tells me it is very likely NOT related to GSAP. 


I wonder if you're dynamically loading content in after the window's "load" event which is affecting layout and therefore changing where the ScrollTrigger start/end values should be. Perhaps try calling ScrollTrigger.refresh() after you're POSITIVE that your page is completely done with its layout tasks (height is set). 🤷‍♂️


Otherwise, please provide a minimal demo that shows the issue and we'd be happy to take a peek for any GSAP-related questions. 

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.