How to detect scroll in modal bootstrap?

Asked

Viewed 105 times

0

Follow my CSS code:

.modal-body {
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

Follows JS code:

$('.modal-body').on('scroll', function () {
    console.log('scroll y');
});

JS code not working, some solution ?

  • This modal is already included in the page from the beginning or you place its element after loading ?

  • @Anthraxisbr found the solution, see my answer.

1 answer

1


I found the solution:

$('#minhaModal').on('shown.bs.modal', function(e) {
  $('.modal-body').on('scroll', function() {
    console.log('scroll y');
  });
})
  • Wow, how strange to work like this, use an event to trigger another event, but the important thing is to work kk tests by putting $(Document). on('scroll','. modal-body',Function( to see if it also works only for testing, without putting the 'Shown.bs.modal', then I think you can with one shot

  • I tested the code: $(document).on('scroll', '.modal-body', function () {console.log("scroll y");}); didn’t work :/, it should work. There’s something secret that I don’t see.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.