Bootstrap Modal with active background and should not close when clicked outside

折月煮酒 提交于 2020-01-11 14:00:09

问题


I am designing a Modal that stick to the bottom of the Mobile screen to give user some tips. So essentially that (non intrusive kind of) Modal should have two properties,

  • Active background (User continue doing what she wants and should not be forced to read)
  • Modal should not be closed when tapped/clicked outside

I am able to achieve either of the behaviors but not both at the same time. I referred this and this but no luck so far..

I am using Bootstrap 3.3.5. Here is the JSFiddle..

<!-- Button to trigger modal -->
<a href="#myModal" role="button" data-backdrop="static" data-keyboard="false" class="btn" data-toggle="modal">Launch Modal</a>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
  <div class="modal-body">        
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
   Modal Test
  </div>
</div>

回答1:


add a attribute in your modal trigger a as data-backdrop="static" and data-keyboard="false"

  <a id="idModal" class="modal"  data-backdrop="static" data-keyboard="false" href="#">

this will keep it alive if clicked outside the modal

remove this div from the page when you click on a

 $("#idModal").on("click",function(){   

   // div that we need to remove 
   //  <div class="modal-backdrop fade in"></div>
        $("div.modal-backdrop").remove();
 })


来源:https://stackoverflow.com/questions/31852891/bootstrap-modal-with-active-background-and-should-not-close-when-clicked-outside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!