Jump to content
GreenSock

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

Draggable fires endless rAF

Recommended Posts

Hi all,

I am trying to solve issue with Draggable. I run performance test on my site and I am able to see rendering tasks on main-thread, but page should be in idle state. I know GSAP has something like autoSleep but it seems that this not work for Draggable. Browser is doing uneccessary work. On weaker computers fan is running and on mobile devices the batery is warming and consuming.

Is there any way how to impove it? I tryied .disable method but it not help.
Thanks for help.

1356810435_Produktyvparku-CSBeton2021-10-1420-47-34.thumb.png.406b6693c768f35f6d7743322d473f6c.png

Produkty v parku - CS Beton 2021-10-14 20-48-23.png

Link to comment
Share on other sites

My best guess (without a minimal demo) is that it's InertiaPlugin, because you have inertia: true. That plugin must constantly track the properties (typically "x" and "y") to know their velocity at any given time. You can enable/disable that using the InertiaPlugin.track() and untrack() methods:

InertiaPlugin.track("#element", "x,y");
InertiaPlugin.untrack("#element", "x,y");

Other than that, yes, GSAP will eventually autoSleep when there haven't been any GSAP animations for a while. Even if it didn't sleep, that wouldn't take up much processing at all. It's super cheap. So if your device's fans kick on, you've almost surely got something else going on that's not just GSAP or Draggable being idle. 

  • Like 1
Link to comment
Share on other sites

@GreenSock thanks for replay. I understand how inertia works but I expected that it tracks only if draggable is actived = dragStart event is fired. Is it safe manipulate with InertiaPlugin when Draggable handles it internally? If yes i will do it in callbacks.

 

Link to comment
Share on other sites

In order for the inertia calculations to be accurate, it must have at least a few hundred milliseconds of historical data to deal with. That's why InertiaPlugin keeps tracking the value(s) - there's no way to know exactly when the user is going to drag so that it can start recording beforehand adequately. But yeah, you can manually track()/untrack() if you're confident you can do it at least about a half-second before the properties start changing :)

  • Like 1
Link to comment
Share on other sites

@GreenSock Ok, thanks for you time. I will combine it with IntersectionObserver. It should work well.

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