G
G
Gera112020-08-17 22:59:29
JavaScript
Gera11, 2020-08-17 22:59:29

How to add an overlay for collapse in bootstrap5?

As you know, bootstrap 5 dropped support for jquery and runs on javascript.
There are collapse blocks that open or hide on the click of a button. I did it my way. on button click, css overlay class is added to body. I wanted to make it disappear by clicking outside the collapse block, i.e. by clicking on the block with the overlay class. But I can't do it in js.
How to make the collapse block hide when clicking on the block with the overlay class?
bootstrap 5 collapse

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gera11, 2020-08-17
@Gera11

I decided on my own, and even on jquery. Who needs this:

$(document).mouseup(function (e){
    var div = $("#collapseExample");
    if (!div.is(e.target)
        && div.has(e.target).length === 0) {
      if($("#collapseExample").hasClass("show")){
        div.collapse('toggle');
      }
      $('#maine').removeClass('maine');
      $('#srch').removeClass('active');
    }
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question