Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
Bootstrap accordion, scroll to top of active accordion on click without bouncing back?

I'm adapting a Bootstrap accordion and trying to move the clicked open accordion to the top of the screen.

I am using this solution

When I click on an accordion and another one is open above the clicked one moves out of the screen and then back into it. I do understand that this is because the first open accordion gets closed and the new clicked one moves into that place before it gets pushed down to the top of the screen.

It's in all the solutions on the post I've linked. Is there a way to click on an accordion and it just stays on top of the screen, even when the content before it is closed?

Here is the same problem shown: JSFiddle snippet
click on item 2, scroll down, click on item 3 and item 3 goes off screen and bounces back. It would be so much nicer if it just stayed on top.

With little text it's fine but it looks not that good if there is loads of content in the accordions.

$('.panel-collapse').on('show.bs.collapse', function(e) {
        var $panel = $(this).closest('.panel');
        var $open = $(this).closest('.panel-group').find('.panel-collapse.in');
        var headerHeight =  $('.menu-container').outerHeight();
        
        var additionalOffset = 0;
        if($panel.prevAll().filter($open.closest('.panel')).length !== 0)
        {
              additionalOffset =  $open.height();
        }
        $('html,body').animate({
          scrollTop: $panel.offset().top - additionalOffset - headerHeight
        }, 500);
      });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda