Bootstrap Modal Backdrop Remaining

前端 未结 24 1923
被撕碎了的回忆
被撕碎了的回忆 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: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.

提交回复
热议问题