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

131
Visualizações
How to make function work only for one button? Bootstrap-5 scroll to modals bottom

What I want to achieve is to create two buttons: 1: that opens modal window 2: opens same modal and scrolls to bottom

code:

$('#menu-item-6706').on('click', function (){
    $('#exampleModal').on('shown.bs.modal', function (event) {
        $("#exampleModal .modal-body").animate({ scrollTop: $('#exampleModal .modal-body').prop("scrollHeight")}, 'slow');
    });
});

Here is full jsfiddle snippet: https://jsfiddle.net/mkx2auhj/1/

Script is almost working:

If you trigger for the the first time “launch demo modal” it opens modal. If you trigger “Contact” it opens modal and scrolls to bottom. So it’s correct.

The problem is if you hit “launch demo modal” again it scrolls to bottom again, which is not desirable. I want it to open standard modal like the first time.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Have a bunch of buttons that all trigger the same modal with slightly different contents? Use event.relatedTarget and HTML data-bs-* attributes to vary the contents of the modal depending on which button was clicked. https://getbootstrap.com/docs/5.1/components/modal/#varying-modal-content

Move the 'shown.bs.modal' event listener outside the click event and use event.relatedTarget to detect when the "Contact" button toggles the modal and then animate the modal accordingly. Try this

$('#exampleModal').on('shown.bs.modal', function (event) {
    if( $(event.relatedTarget).is('#menu-item-6706') ){
        $("#exampleModal .modal-body").animate({ 
            scrollTop: $('#exampleModal .modal-body').prop("scrollHeight")
        }, 'slow');
    }
});
about 4 years ago · Juan Pablo Isaza Relatório
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