Bootstrap Modal Backdrop Remaining

前端 未结 24 1924
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 08:55

I am showing a Bootstrap modal window for loading when performing AJAX calls. I broadcast a \"progress.init\" event when the loading modal should show and a \"progress.finis

相关标签:
24条回答
  • 2020-12-23 09:28

    Add data-backdrop="false" option as an attribute to the button which opens the modal.

    See How to remove bootstrap modal overlay?

    0 讨论(0)
  • 2020-12-23 09:30

    If the close dismiss button is working but the problem occurs when using dynamic code such as modal('hide') you can use this code. forcing the backdrop to totally remove.

    for Bootstrap 3

    $modal.on('hidden.bs.modal', function(){
      //remove the backdrop
      jQuery('[data-dismiss="modal"]').click();
    });
    
    yourbutton.click(function() {
      $modal.modal('hide');
    });
    
    0 讨论(0)
  • 2020-12-23 09:31

    Workaround is to hide the backdrop entirely if you don't need one like this: data-backdrop=""

    <div class="modal fade preview-modal" data-backdrop="" id="preview-modal"  role="dialog" aria-labelledby="preview-modal" aria-hidden="true">
    
    0 讨论(0)
  • 2020-12-23 09:32

    So if you don't want to remove fade or tinker with the dom objects, all you have to do is make sure you wait for the show to finish:

    $('#load-modal').on('shown.bs.modal', function () {
        console.log('Shown Modal Backdrop');
        $('#load-modal').addClass('shown');
    });
    
    function HideLoader() {
        var loadmodalhidetimer = setInterval(function () {
            if ($('#load-modal').is('.shown')) {                
                $('#load-modal').removeClass('shown').modal('hide');
                clearInterval(loadmodalhidetimer);
                console.log('HideLoader');
            }
            else { //this is just for show.
                console.log('Waiting to Hide');
            }
        }, 200);
    }
    

    IMO Bootstrap should already be doing this. Well perhaps a little more, if there is a chance that you could be calling hide without having done show you may want to add a little on show.bs.modal add the class 'showing' and make sure that the timer checks that showing is intended before getting into the loop. Make sure you clear 'showing' at the point it's shown.

    0 讨论(0)
  • 2020-12-23 09:33

    An issue I was having (may help someone) was simply that I was using a partial to load the Modal.

    <li data-toggle="modal" data-target="#priceInfoModal">
    <label>Listing Price</label>
    <i class="fa fa-money"></i>
    @Html.Partial("EditPartials/PriceInfo_Edit")
    </li>
    

    I had placed the partial call inside the same list item So data-target="#priceInfoModal" and div id="priceInfoModal" were in the same container causing me to not be able to close my modal

    0 讨论(0)
  • 2020-12-23 09:35

    Use a close button in modal, this method is working fine:

    <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel" id="close_model">
    

    After success use:

    $('#model_form').trigger("reset"); // for cleaning a modal form
    $('#close_model').click(); // for closing a modal with backdrop
    
    0 讨论(0)
提交回复
热议问题