【问题标题】:Keep query string from automatically scrolling down防止查询字符串自动向下滚动
【发布时间】:2021-11-30 14:57:13
【问题描述】:

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

<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,它将加载打开安全选项卡的页面。问题是当您加载该链接时,它会自动向下滚动到页面的该部分。我想确保链接在页面顶部打开并保持在那里,直到用户向下滚动。有什么想法吗?

【问题讨论】:

  • “直到用户向下滚动”是什么意思?当用户开始滚动任何地方时,您想自动滚动到该元素吗?

标签: javascript html jquery elementor


【解决方案1】:

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

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

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

【讨论】:

  • 谢谢!这解决了它!
猜你喜欢
  • 2016-08-24
  • 2015-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-05
  • 1970-01-01
  • 1970-01-01
  • 2021-09-03
相关资源
最近更新 更多