Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific modal-backdrop customizing

I can change the CSS for one of many modals in my page by setting as selector the id of that specific modal.

e.g. instead:

.modal {
    top: 0px;
    margin-top: 240px;
    ...
}

setting

#my_modal {
    top: 0px;
    margin-top: 240px;
    ...
}

My question:

How can I change the css for only #my_modal's corresponding .modal-backdrop element?

 $('.modal').addClass('my_personal_stuff');

works, while

 $('.modal-backdrop').addClass('my_personal_stuff');

doesn't works

Why the behavior is so?

like image 391
bentzy Avatar asked Oct 15 '25 16:10

bentzy


2 Answers

How can I change the css for only #my_modal's corresponding modal-backdrop?

// Add an extra class to the modal backdrop to make it customizable
$('.modal--custom').on('show.bs.modal', function (e) {
    setTimeout(function(){
        $('.modal-backdrop').addClass('modal-backdrop--custom');
    });
}); 

This works for me. Check out this jsFiddle.

like image 163
Double U Age Avatar answered Oct 18 '25 10:10

Double U Age


You need to bind the show and hide evento of your modal and add a class to .modal-backdrop div.

Jsfiddle here.

Javascript

function haveBackdrop() {
    if ($('.modal-backdrop').length > 0) {
        $('.modal-backdrop').addClass('my-modal-backdrop');
        clearTimeout(mBackdrop);
        return true;
    }
    return false;
}
var mBackdrop;

$('#myModal').on('show', function() {
    mBackdrop = setTimeout("haveBackdrop()", 100);
});

CSS

.my-modal-backdrop { /* your css backdrop modifications */ }
like image 44
Oswaldo Acauan Avatar answered Oct 18 '25 12:10

Oswaldo Acauan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!