I wrote a script so that when you click on the link anchor, the scroll smoothly transfers to the item. This is where the scrolling problem goes smoothly and there is no problem, but when you click again on the same link, the scrolling option stupidly disappears, that is, by turning the mouse wheel or dragging the scroll, everything stupidly stands still and does not move, but after several attempts it passes. In the console, it is purely therefore I don’t even have thoughts because of this problem.

//Anchor Scroll $(document).ready(function() { $('a[href^="#"]').click(function(event) { event.preventDefault(); elementClick = $(this).attr("href"); destination = $(elementClick).offset().top; var scrolling = destination - 100; $('html,body').animate( { scrollTop: scrolling }, 500 ); }); }); 
  • When you click on the link that should scroll? or any? or with a double click on the button? - Skywave

1 answer 1

A rather stupid mistake, with a few clicks on the link, several animations are launched, so until the time passes, there is no possibility of scrolling at all, so just set the condition for comparing the position of the element and the scroll so that the animation does not start:

 $('a[href^="#"]').click(function(event){ event.preventDefault(); clickElement = $(this).attr("href"); destination = $(clickElement).offset().top; var scrolling = destination - 100; scrolling = parseInt(scrolling); var position = $(window).scrollTop(); position = parseInt(position); if(scrolling != position){ $('html,body').animate({ scrollTop: scrolling}, 500); } });