Closing Modal Popup by Clicking Away from It

前端 未结 2 1382
Happy的楠姐
Happy的楠姐 2020-12-22 04:42

I am using this tutorial to add a modal screen:

http://raventools.com/blog/create-a-modal-dialog-using-css-and-javascript/

Everything works great except clos

相关标签:
2条回答
  • 2020-12-22 04:49

    Try this:

    $(document).ready(function(){
    $('#overlay').bind('click', function(event){
        if (event.target == $('#overlay').get(0))
            overlay(); 
    });
    
    0 讨论(0)
  • 2020-12-22 05:09

    You will have to move the code of the the overlay from the modal window. Separating this, you will not have the overlay as a parent of the window and the click event will trigger only on the overlay.

    <div id="overlay"> </div>
    <div id="modalWindow">
        <p>Content you want the user to see goes here.</p>
    </div>
    
    0 讨论(0)
提交回复
热议问题