1

There is an accordion with buttons when you click on which this or that block appears. The problem is that when switching blocks, the page twitches as it scrolls to the anchors. How to remove scroll when switching blocks?

I didn't add blocks because they are too big.

Maybe I didn't write the code correctly?

Here are the buttons themselves:

<div class="goods_button">
  <li><a href="#tab1">Specifications</a></li>
  <li><a href="#tab2">Support & Downloads</a></li>
  <li><a href="#tab3">Gallery</a></li>
  <li><a href="#tab4">Test results</a></li>
</div>

And here is the jquery code for the toggle:

$(document).ready(function($) {
  $('.goods_block').hide();
  $('.goods_block:first').show();
  $('.goods_button li:first').addClass('block-active');
  
  $('.goods_button li').click(function(event) {
    $('.goods_button li').removeClass('block-active');
    $(this).addClass('block-active');
    $('.goods_block').hide();
    var selectTab = $(this).find('a').attr("href");
    $(selectTab).fadeIn();
  });
});

you need to remove the scroll when switching blocks, the page jumps

biberman
  • 5,606
  • 4
  • 11
  • 35
  • Add `return false;` as the last line of your click handler: `$(selectTab).fadeIn(); return false;` – freedomn-m Nov 21 '22 at 11:55
  • Does this answer your question? [event.preventDefault() vs. return false](https://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false) – freedomn-m Nov 21 '22 at 13:13

0 Answers0