How to make modal close on click outside

后端 未结 7 717
误落风尘
误落风尘 2020-12-19 02:05

I have used this JavaScript below:

7条回答
  •  清酒与你
    2020-12-19 02:55

    Simple:

    var images_modal = document.getElementById('images-model-div');

    var videos_modal = document.getElementById('video-model-div');

    // When the user clicks anywhere outside of the modal, close it

    window.onclick = function(event) {

    if (event.target == images_modal) {

    images_modal.style.display = "none";

    }

    if (event.target == videos_modal) {

    videos_modal.style.display = "none";

    }

    }

提交回复
热议问题