Sapoios
Coder
Hello guys i would like a help with a problem that i cant fix.
I have a horizontal bar with categories. Its category is a link to a page section.
This bar is made for mobile so its full width is beyond screen.
Now i have an event listener that detecta scroll distance of visitor and when finds the section of a link adds a class to make it "active" and bring the corresponding bar element to center of view.
This is achieved with a foreach loop inside listener that checks all the link of categories and if one is between a range of pixels add class active and scrollintoview. Else just remove class active.
The categories are counted before listener because it might be different each time so currently i have 21.
This means that gor every pixel scroll i check 21 links and have 21 results 1 that adds a class and 20 that removes it.
The problem i have is with scrollintoview in which i use options behavior : smooth and inline : center. That normal animates a scroll effect that brings the element into center. Now because i use smooth the animation only happens afrer the scroll ends because scrollintoview view is called far to many times wilhile scrolling. If a left it on auto it works but it jumps right into it with out animation effects.
Is the any way to scroll into view only for the element with the class active or if this element already has active run only once for this element?
I have a horizontal bar with categories. Its category is a link to a page section.
This bar is made for mobile so its full width is beyond screen.
Now i have an event listener that detecta scroll distance of visitor and when finds the section of a link adds a class to make it "active" and bring the corresponding bar element to center of view.
This is achieved with a foreach loop inside listener that checks all the link of categories and if one is between a range of pixels add class active and scrollintoview. Else just remove class active.
The categories are counted before listener because it might be different each time so currently i have 21.
This means that gor every pixel scroll i check 21 links and have 21 results 1 that adds a class and 20 that removes it.
The problem i have is with scrollintoview in which i use options behavior : smooth and inline : center. That normal animates a scroll effect that brings the element into center. Now because i use smooth the animation only happens afrer the scroll ends because scrollintoview view is called far to many times wilhile scrolling. If a left it on auto it works but it jumps right into it with out animation effects.
Is the any way to scroll into view only for the element with the class active or if this element already has active run only once for this element?