Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda