{"id":201,"date":"2025-06-23T11:09:09","date_gmt":"2025-06-23T11:09:09","guid":{"rendered":"https:\/\/webprow.com\/blog\/?p=201"},"modified":"2025-07-01T14:04:31","modified_gmt":"2025-07-01T14:04:31","slug":"smooth-scrolling-isnt-functioning-properly-when-you-click-on-the-navigation-menu-links-that-lead-to-different-sections-on-the-same-page","status":"publish","type":"post","link":"https:\/\/webprow.com\/blog\/smooth-scrolling-isnt-functioning-properly-when-you-click-on-the-navigation-menu-links-that-lead-to-different-sections-on-the-same-page\/","title":{"rendered":"Smooth scrolling functionality to different sections on the same page"},"content":{"rendered":"\n<p>Smooth scrolling isn&#8217;t functioning properly when you click on the navigation menu links that lead to different sections on the same page? Below is the solution<\/p>\n\n\n\n<p>Will make the smooth scroll easily by using below steps<br><strong>Step 1: HTML <\/strong><br>Create a straightforward one-page layout that includes internal navigation links<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;nav&gt;<br>    &lt;a href=\"#about\"&gt;About&lt;\/a&gt;<br>    &lt;a href=\"#services\"&gt;Services&lt;\/a&gt;<br>    &lt;a href=\"#contact\"&gt;Contact&lt;\/a&gt;<br>  &lt;\/nav&gt;<br><br>  &lt;section id=\"about\"&gt;<br>    &lt;h2&gt;About Us&lt;\/h2&gt;<br>    &lt;p&gt;Some content...&lt;\/p&gt;<br>  &lt;\/section&gt;<br><br>  &lt;section id=\"services\"&gt;<br>    &lt;h2&gt;Our Services&lt;\/h2&gt;<br>    &lt;p&gt;More content...&lt;\/p&gt;<br>  &lt;\/section&gt;<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Step 2: CSS<\/strong><br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/* style.css *\/<br><br><strong>body <\/strong>{<br>  font-family: sans-serif;<br>  scroll-behavior: auto; \/* will override with jQuery *\/<br>}<br><br>nav {<br>  position: fixed;<br>  top: 0;<br>  background: #333;<br>  width: 100%;<br>  padding: 10px;<br>  text-align: center;<br>}<br><br>nav a {<br>  color: white;<br>  margin: 0 15px;<br>  text-decoration: none;<br>}<br><br>section {<br>  height: 100vh;<br>  padding-top: 60px;<br>}<br><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Step 3: <strong>jQuery<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ script.js<br><br>$(document).ready(function () {<br>  $('nav a').click(function (e) {<br>    e.preventDefault(); \/\/ Stop default jump<br>    const target = $(this).attr('href'); \/\/ Get the section ID<br>    $('html, body').animate(<br>      {<br>        scrollTop: $(target).offset().top<br>      },<br>      800 \/\/ Duration in milliseconds<br>    );<br>  });<br>});<br><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Hope this helps. Please mention in comments if any queries<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Smooth scrolling isn&#8217;t functioning properly when you click on the navigation menu links that lead to different sections on the same page? Below is the solution Will make the smooth scroll easily by using below stepsStep 1: HTML Create a straightforward one-page layout that includes internal navigation links &lt;nav&gt; &lt;a href=&#8221;#about&#8221;&gt;About&lt;\/a&gt; &lt;a href=&#8221;#services&#8221;&gt;Services&lt;\/a&gt; &lt;a href=&#8221;#contact&#8221;&gt;Contact&lt;\/a&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":202,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,7,27],"tags":[29,31,30,28],"class_list":["post-201","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-html","category-js-jquery","tag-scroll-behavior","tag-scrollintoview","tag-single-page-navigation","tag-smooth-scrolling"],"_links":{"self":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts\/201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/comments?post=201"}],"version-history":[{"count":3,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts\/201\/revisions"}],"predecessor-version":[{"id":206,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/posts\/201\/revisions\/206"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/media\/202"}],"wp:attachment":[{"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/media?parent=201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/categories?post=201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webprow.com\/blog\/wp-json\/wp\/v2\/tags?post=201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}