Currently, I have implemented a smooth scrolling effect on my website using the following jQuery code:
jQuery('html,body').animate({scrollTop:scrollTarget}, 1000, "swing");
Although the effect works well in general, I have noticed that when multiple items are clicked rapidly, it sometimes causes a brief flash of content on the page for a second. This issue can be experienced on the following link: . Try clicking on Services and then rapidly clicking on Contact multiple times. You will notice that the Services area briefly flashes, which is not ideal and I am looking for a solution to fix this.
My ultimate goal is to somehow introduce a delay in the execution of the scrolling effect. Currently, I have added a condition check:
if(parseInt(scrollTarget) !== parseInt(jQuery(window).scrollTop())) {
This condition helps prevent scrolling to the same area, but I would like the scrolling to fetch the correct scrolltop and scrolltarget values after the initial scroll rather than using the values when it was initially clicked. For example, if you click on Contact multiple times while in the Services section, I would like it to scroll to Contact first and then use the updated values for subsequent scrolls.
Any suggestions or ideas on how to achieve this would be highly appreciated.