防止查询字符串自动向下滚动

Keep query string from automatically scrolling down

我正在使用此脚本在页面加载时使用媒体字符串自动打开 elementor 切换小部件中的特定选项卡。

<script>


document.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {

jQuery(function($){
let toggletitles = $('.elementor-toggle-item .elementor-tab-title');

let strings = ['?technical',
'?configuration',
'?safety',
'?cycle-life',
'?discharge',
'?charging',
'?environmental',
'?mechanical'
];

strings.forEach( (string,i) => {
if (window.location.href.indexOf(string) > -1) {
toggletitles.eq(i).click();
$('html, body').animate({
scrollTop: toggletitles.eq(i).offset().top - 100
},'slow');
} } );
}); }, 1200); });
</script>

因此,如果我输入 url https://electrovolt.com/prislogic-4s1p-120-ah/?safety,它会在打开安全选项卡的情况下加载页面。问题是当您加载 link 时,它会自动向下滚动到页面的该部分。我想确保 link 在页面顶部打开并停留在那里,直到用户向下滚动。有什么想法吗?

下一行是导致浏览器页面动画“向下滚动”效果到页面上小部件所在位置的原因:

$('html, body').animate({
scrollTop: toggletitles.eq(i).offset().top - 100
},'slow');

如果删除该行,您的页面将不再向下滚动。