Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POST] native dialog element #27

Open
Rplus opened this issue Mar 21, 2016 · 0 comments
Open

[POST] native dialog element #27

Rplus opened this issue Mar 21, 2016 · 0 comments
Labels

Comments

@Rplus
Copy link
Owner

Rplus commented Mar 21, 2016

dialog 雖然支援度有點差
( 目前只有 blink 系列支援
http://caniuse.com/#feat=dialog

不過它的行為還蠻好玩的~
就像 native form 一般,屬於有互動功能的元素

可以在這頁玩個一圈就大概知道有哪些趣味的東西了
http://demo.agektmr.com/dialog/

native style
image

.show() and .close() API

可以簡單控制 show / hide
它會 trigger [open] 這個 attribute

.showModal() API

若改用 showModal 可以有一層半透明的 pseudo-element ::backdrop 壓在後面

::backdrop 可以用 CSS 控制樣式

點擊到 pseudo-element 時,click event 會傳到 dialog 身上
這時可以藉由點擊位置來判斷是不是點在 pseudo-element 上頭~
ref: http://stackoverflow.com/a/30744005/5940513

close event

close 時的參數,可以在 close event 裡用 this.returnValue 拿到~

document.querySelector('#close').onclick = function() {
  var value = document.querySelector('#return_value').value;
  dialog.close(value);
};
document.querySelector('dialog').addEventListener('close', function() {
  alert(this.returnValue);
});

這有點像是在模擬 window.confirm 的功能,
不過 window.confirm / alert / prompt 會影響到整個視窗的操作,很干擾
而用 notification 的話,又太小 & 時間很難控制,再加很難點...
(( 很難點掉真的超煩...


ref:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog

@Rplus Rplus added bug 筆記 and removed bug labels Mar 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant