jquery anchor effect does not work properly

I have the following script that provides an anchor effect:

// Smooth scrolling when clicking on a hash link
$(‘a[href*=”#”]’).on(‘click’, function (e) {
e.preventDefault();

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

if ($(window).width() > 1023) {
var $scrollTop = $target.offset().top – 120;
} else {
var $scrollTop = $target.offset().top;
}

$(‘html, body’).stop().animate({
‘scrollTop’: $scrollTop
}, 900, ‘swing’);
});

The problem is that this only works on home page, but in the other pages it does not work because I need to provide the web link (www.url.com/#anchor). But if I do this, the effect does not apply. someone knows how to add to the effect, for example get_site_url (‘/#anchor/’); , and so this always take the url of the web as a base?

I hope I have expressed myself well.
Greetings and thanks

Read more here:: jquery anchor effect does not work properly

Leave a Reply

Your email address will not be published. Required fields are marked *