์ ํ
์ฐธ์กฐ๋ฌธ์
์ฃผ์
HTML Dom Api
์๋ฒ
1
ํ๊ทธ
์ค๋ช
๋ ์ง
๐https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
๋ชจ๋ฌํ์ ์ ํ๊ทธ๋ก ๊ตฌํํ ์ ์๋ค.
esc ํค ๋ฅผ ๋๋ฅด๋ฉด ์ฐฝ๋ซ๊ธฐ ๊ธฐ๋ฅ๋ ์ง์ ํ๋ค.
- ๊ธฐ๋ณธํ ๊ตฌํ
- ์ค๋ฒ๋ ์ด ๋ฐฐ๊ฒฝ์ถ๊ฐ
<dialog open>
<p>์คํฌ๋ฆฝํธ ์์จ๋ ์ ๋ง ๋๋ค๊ตฌ?</p>
<form method="dialog">
<button>OK</button>
</form>
</dialog>
ok๋ฒํผ ํด๋ฆญ์ ์ฐฝ์ด ๋ซํ๋ค.
<dialog>
<button autofocus>Close</button>
<p>์ด๋ฒ์ ๋ฐฐ๊ฒฝ์ ๋ฃ๊ธฐ</p>
</dialog>
<button>์์</button>
::backdrop {
background-image: linear-gradient(
45deg,
magenta,
rebeccapurple,
dodgerblue,
green
);
opacity: 0.75;
}
::backdrop
์ ํ์๋ dialog ์์์ ๋ฐฐ๊ฒฝ์์ ์ ํํ ์ ์๋ค.
์์ฃผ ์ฝ๊ฐ์ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๊ฐํ๋ค
const dialog = document.querySelector("dialog");
const showButton = document.querySelector("dialog + button");
const closeButton = document.querySelector("dialog button");
// "Show the dialog" button opens the dialog modally
showButton.addEventListener("click", () => {
dialog.showModal();
});
// "Close" button closes the dialog
closeButton.addEventListener("click", () => {
dialog.close();
});
showModal(), close() ๋ dialog api ๊ฐ ์ ๊ณตํ๋ ๋ฉ์๋์ด๋ค.