Jimmy
Jimmy

Reputation: 12497

Lagging JavaScript - Opportunity for optimization or less expensive functions

I have this code and it works exactly as I want. The menu bar sits on top and recognizes the section it is on or in. You can click the links in the yellow menu to move between the sections.

However, the code itself gets quite laggy as soon as you start putting any content in the boxes. I wondered if there is any opportunity to optimize the code and make it run a bit smoother.

Upvotes: 1

Views: 71

Answers (1)

Tibos
Tibos

Reputation: 27843

The problem you have is that you're repeatedly changing page layout properties (via the animation) and querying page layout properties (in the scroll handler), thus triggering a large number of forced layouts.

If i understand your code correctly you could get a big improvement by disabling the scroll handler during the click animation and instead triggering the effects with no checks made (set the active class on the clicked element).

Upvotes: 2

Related Questions