# Issue with Custom Code for Smooth Scroll

**URL:** <https://forum.readymag.com/t/issue-with-custom-code-for-smooth-scroll/2128>\
**Category:** Custom code\
**Created:** [October 29, 2023, 6:06pm UTC](https://forum.readymag.com/t/issue-with-custom-code-for-smooth-scroll/2128 "2023-10-29T18:06:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kim\_Gryun](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/kim_gryun/32/1206_2.png) [@Kim\_Gryun](https://forum.readymag.com/u/Kim_Gryun)\
**Post date:** [October 29, 2023, 6:06pm UTC](https://forum.readymag.com/t/issue-with-custom-code-for-smooth-scroll/2128/1 "2023-10-29T18:06:48Z")

</div>

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:**

```auto
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

```

1. **Before the `</body>` tag** :

```auto
<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

---

<div class="post-metadata">

**Author:** ![neueMeta](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/neuemeta/32/92_2.png) [@neueMeta](https://forum.readymag.com/u/neueMeta)\
**Post date:** [October 30, 2023, 1:07pm UTC](https://forum.readymag.com/t/issue-with-custom-code-for-smooth-scroll/2128/2 "2023-10-30T13:07:44Z")

</div>

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.
