Hide Bootstrap modal in mobile

主宰稳场 提交于 2019-12-06 01:49:11

Your media query is overwritten by jQuery. Try it with jQuery.

something like this:

$('#myModal').on('shown.bs.modal', function () {
    var width = $(window).width();  
    if(width < 480){
        $(this).hide(); 
    }
});

as you said that your css is not working i would recommend using jquery method just add this before the modal html code <div class='check-width'>, and use the below script.

if($('.check-width').width() == 500){
   $('#myModal').modal('hide'); 

}
else{

}

Danko's answer above still left the darkened overlay on my page (even though no modal appeared) but this is what worked for me:

    $('#myModal').on('shown.bs.modal', function () {
        var width = $(window).width();  
        if(width < 768){
            $('#myModal').modal('hide') 
        }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!