I am using jQuery + jQuery UI and currently have the following code:-
$(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
}, 1000);
return false;
}
}
});
});
I get the scrolling effect when the scroll to is on the same page, but if I load a new page it doesn't scroll to that section, e.g. from /home/ to /about/#section3
How can I get this to work for both on same page anchors and scroll to anchor when loading a new page?