gpt4 book ai didi

javascript - 平滑的页面滚动不适用于所有语言(即更改的 URL 结构)

转载 作者:行者123 更新时间:2023-12-01 01:44:19 24 4
gpt4 key购买 nike

我有一个 js,当单击“更多”按钮时,它可以将页面平滑滚动到另一个位置。

它可以工作,但如果为站点选择了另一种语言,则无效。当用户更改语言(例如更改为西类牙语)时,URL 会更改为 www.example.com/ES。这似乎破坏了在 www.example.com 上运行的平滑滚动。

单击西类牙语的更多链接似乎会在滚动位置完全重新加载页面,但不会平滑滚动。

这是我的js。如何在平滑滚动中包含替代语言 url?

(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);

编辑:作为引用,该脚本在 Wordpress 的functions.php 中排队,我使用的语言插件称为 qTranslate

最佳答案

尝试更改这部分:

$('a[href*=#]:not([href=#])')

此选择器正在选择所有标签,请尝试向其中添加一个类。像这样的事情:

$('.more a[href*=#]:not([href=#])')

该函数应该位于您的 .js 文件中,而不是位于functions.php 文件中。如果您有不同的语言,则不应影响您所拥有的脚本。

关于javascript - 平滑的页面滚动不适用于所有语言(即更改的 URL 结构),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472467/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com