try this
$('.modal').on('hide.bs.modal', function () {
if ($(this).is(':visible')) {
console.log("show modal")
$('.modal-backdrop').show();
}else{
console.log("hidden modal");
$('.modal-backdrop').remove();
}
})