Jump to content
GreenSock

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

Recalculate scrolltrigger on ajax append

Recommended Posts

Hey Tigranchik and welcome to the GreenSock forums. It's really hard to debug a live website. If you'd like our help debugging please make a minimal demo of the issue as this post discusses:

 

Link to comment
Share on other sites

Hey Tigranchik,

 

maybe it is just a matter of syntax, if you are using scrolltrigger.refresh()

 

Does

 

ScrollTrigger.refresh();

 

maybe work for you?

 

  • Like 1
Link to comment
Share on other sites

The .refresh() call should come in the callback of your AJAX request after the content has been appended to the page. Without code enough to recreate the situation I don't know if we can help you any further.

Link to comment
Share on other sites

 

I think it does work, but it only refreshes the ScrollTriggers, that you have already created.

 

There are no ScrollTriggers set for the fresh appended elements, so you would have to create them first. 

Before that you should probably kill off the old ScrollTriggers, though, so you don't keep apllying new ScrollTriggers over the old again and again.

 

Not sure if I am 100% correct on the above said and if this is the go-to solution, but it works

 

See the Pen f5354d1243728ef70a7b7827e0eb6927 by akapowl (@akapowl) on CodePen

 

  • Like 1
Link to comment
Share on other sites

In addition to what Paul said, you can save a reference to the ScrollTrigger to prevent having to kill and recreate it each time. This just refreshes ones that exist already (which isn't actually necessary in your situation since all the content is positioned after the old ScrollTriggers):

See the Pen bGpPWay?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

Okay, thank you for helping guys, in any case it doesn't work as we would like, but thanks anyway)

Link to comment
Share on other sites

5 minutes ago, Tigranchik said:

it doesn't work as we would like

What way would you like it to work? 

Link to comment
Share on other sites

I tried both examples, but when adding new elements to the page, scrolltrigger does not want to work with them, I don’t know if it is possible to repeat a similar code on the codepen with a ajax request to another page

Link to comment
Share on other sites

Just now, Tigranchik said:

I don’t know if it is possible to repeat a similar code on the codepen with a ajax request to another page

It is. You just have to create/refresh the ScrollTriggers once the content is in the page.

Link to comment
Share on other sites

Please make a minimal demo that recreates the issue if you'd like further help debugging.

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.

×