Home > Mobile >  Keep query string from automatically scrolling down
Keep query string from automatically scrolling down

Time:10-12

I'm using this script to automatically open specific tabs in an elementor toggle widget on page load using media strings.

<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>

So if I were to enter the url https://electrovolt.com/prislogic-4s1p-120-ah/?safety it would load the page with the safety tab open. The problem is that when you load that link, it automatically scrolls down to that section of the page. I'd like to make sure that the link opens at the top of the page and stays there until the user scrolls down. Any ideas?

CodePudding user response:

The following line is what is causing the browser page to animate a "scroll down" effect to where the widget is on the page:

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

If you remove that line, your page should no longer scroll down.

  • Related