I have a js that animates a smooth page scroll to another location when a more button is clicked.
It works, but not if another language for the site is selected. When a user changes language, say, to Spanish, the URL changes to www.example.com/ES. This seems to break the smooth scroll, which works on www.example.com.
Clicking the more link in Spanish seems to completely reload the page, in the scroll location, but without the smooth scrolling.
Here is my js. How can I include the alt language url in the smooth scroll?
(function($){
$(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;
}
}
});
});
})(jQuery);
Edit: For reference the script is enqueued in Wordpress' functions.php and the language plugin I am using is called qTranslate