Answers for "smooth scroll href jquery"

0

Smooth Scrolling' to Anchor Links With Jquery

<script>
  jQuery($ => {
    // The speed of the scroll in milliseconds
    const speed = 1000;

    $('a[href*="#"]')
      .filter((i, a) => a.getAttribute('href').startsWith('#') || a.href.startsWith(`${location.href}#`))
      .unbind('click.smoothScroll')
      .bind('click.smoothScroll', event => {
        const targetId = event.currentTarget.getAttribute('href').split('#')[1];
        const targetElement = document.getElementById(targetId);

        if (targetElement) {
          event.preventDefault();
          $('html, body').animate({ scrollTop: $(targetElement).offset().top }, speed);
        }
      });
  });
</script>
Posted by: Guest on December-18-2021
0

smooth scroll jquery

smooth scroll
Posted by: Guest on October-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language