HTML5 CSS3 模态窗口,点击外部关闭

标签 html css cross-browser modal-dialog modal-window

我使用 Keenan Payne 描述的模态窗口,它是用 HTML5 和 CSS3 制作的。 当用户点击模态窗口外的深色背景时,我希望它关闭。有人知道怎么做吗?

Keenan Payne 的模态窗口: http://www.webdesignerdepot.com/2012/10/creating-a-modal-window-with-html5-and-css3/

最佳答案

您必须更改与#openModal 不同的目标。您可以导入 jQuery,将它放在 <head> 中部分:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

并在 </body> 之前添加此代码标签:

<script type="text/javascript">
    $("#openModal").click( function() {
        if (!$("#openModal>div").is(":hover")) document.location.href='#';
    });
</script>

因此,当用户点击叠加层时,目标将更改为“#”并且模式将关闭。

关于HTML5 CSS3 模态窗口,点击外部关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19684599/

相关文章:

css - 绝对定位按钮不会出现在固定标题上

html - CSS - 变换 : rotateX animation not working on mobile browsers (even with -webkit-)

css - SVG 或 HTML 中像素完美一致的文本宽度

javascript - 字段集有效性是什么意思?

javascript - 在 Safari (Windows) 中使用 html5/js 音频时出现问题

javascript - 绝对定位内容的平滑滚动

html - Bootstrap 4 - 在 Ubuntu Chrome 和 Firefox 中呈现的字体大小截然不同

javascript - Bootstrap 按钮动态添加,呈现方式与标记中声明的按钮不同

javascript - 复选框垂直对齐错误 : label is down and the check box is up

html - <ul> 使用 :nth-child to set different color 的问题