I have a navigation and the source url looks like this:
test.php?query=19
and I have links on my page, so <a href="#section-1">Section 1</a><a href="#section-2">Section 2</a><a href="#section-3">Section 3</a>
with three sections:
<section id="section-1"></section><section id="section-2"></section><section id="section-3"></section>
and I use this jquery code to scroll this section at the top of the page (or where the user is on the page) at the top of this section and not show the # tag in my URL.
$(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 2000); return false; } } }); });
My problem is that this is not a scroll to a section. its just goes to the bottom of the section and then scrolls up and # appears in my url.
I have another menu on the main page:
home.php and I use the same jquery code and it works on this page.
My question is: how do I get ScrollTop to work on my page test.php?query=19 , as it does on home.php When I click on similar on test.php?query=19 , my url changes to this: test.php?query=19#section-1
jquery
user979331
source share