如何关闭新的html<对话框>点击其背景标签 [英] How to close the new html <dialog> tag by clicking on its ::backdrop

查看:152
本文介绍了如何关闭新的html<对话框>点击其背景标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有发现任何内置的解决方案或解决方法,通过单击其背景(:: backdrop)来关闭html5元素,尽管这显然是一项基本功能。

I didn't find any built in solution or workaround for closing the html5 element by clicking on its background(::backdrop), although it's clearly a basic functionality.


Backdrop clicks can be detected using the dialog bounding rect.

使用对话框边界矩形可以检测背景点击。 document.getElementByTagName( '对话');
dialog.showModal();
dialog.addEventListener('click',function(event){
var rect = dialog.getBoundingClientRect();
var isInDialog =(rect.top< = event.clientY&& amp ; event.clientY <= rect.top + rect.height
& rect.left< = event.clientX&& event.clientX< = rect.left + rect.width);
if(!isInDialog){
dialog.close();
}
});

var dialog = document.getElementByTagName('dialog'); dialog.showModal(); dialog.addEventListener('click', function (event) { var rect = dialog.getBoundingClientRect(); var isInDialog=(rect.top <= event.clientY && event.clientY <= rect.top + rect.height && rect.left <= event.clientX && event.clientX <= rect.left + rect.width); if (!isInDialog) { dialog.close(); } });

这篇关于如何关闭新的html&lt;对话框&gt;点击其背景标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆