Issue with Custom Code for Smooth Scroll

Hello Readymag Community,

I’ve been trying to implement a smooth scrolling effect (with Customized speed) on my website using custom code.
However, despite placing the code correctly as per recommendations, I’m not getting the desired effect. I’m hoping someone here might have faced a similar challenge and can offer some guidance.

Here’s a breakdown of the custom codes I’ve added:

  1. In the Head section:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  1. Before the </body> tag:
<script>
$(document).on('click', 'a[href^="#"]', function(e) {
    e.preventDefault();

    var target = this.hash;
    var $target = $(target);

    $('html, body').stop().animate({
        'scrollTop': $target.offset().top
    }, 2000, 'swing', function() {
        window.location.hash = target;
    });
});
</script>

Has anyone experienced a similar issue or can spot something I might be missing? Your insights and suggestions would be greatly appreciated.

Thank you in advance for your help!

Best regards,

Gryun Kim

hey. regarding your page order different container-divs are scrolled. So it might not be
$(‘html, body’).
Look into the inspector to get find out whats the container that gets scrolled.