HTMLInputElement: popoverTargetElement ããããã£
Baseline
2024
*
Newly available
Since â¨April 2024â©, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
* Some parts of this feature may have varying levels of support.
popoverTargetElement 㯠HTMLInputElement ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®ããããã£ã§ã<input> è¦ç´ ã® type="button" åã§å¶å¾¡ãããããããªã¼ãã¼è¦ç´ ãåå¾ããã³è¨å®ãã¾ãã
ãã㯠JavaScript ã«ãã㦠HTML ã® popovertarget 屿§ã«ç¸å½ãããã®ã§ãã
å¤
DOM å ã§ã®ããããªã¼ãã¼è¦ç´ ã¸ã®åç §ã§ãã
ä¾
function supportsPopover() {
return HTMLElement.prototype.hasOwnProperty("popover");
}
const popover = document.getElementById("mypopover");
const toggleBtn = document.getElementById("toggleBtn");
const popoverSupported = supportsPopover();
if (popoverSupported) {
popover.popover = "auto";
toggleBtn.popoverTargetElement = popover;
toggleBtn.popoverTargetAction = "toggle";
} else {
console.log("Popover API not supported.");
}
èªåããããªã¼ãã¼ã§ã®ããããªã¼ãã¼ã®åãæ¿ãåä½
ãã®ä¾ã§ã¯ã popoverTargetAction ããããã£ã« "toggle" å¤ãè¨å®ããããããªã¼ãã¼ API ã®åºæ¬çãªä½¿ç¨æ¹æ³ã示ãã¾ãã
popover 屿§ã¯ "auto" ã«è¨å®ããã¦ããã®ã§ãããããªã¼ãã¼ã¯ããããªã¼ãã¼é åã®å¤å´ãã¯ãªãã¯ãããã¨ã§éããããç¶æ
("light-dismissed") ã«ãããã¨ãã§ãã¾ãã
ã¾ããããããªã¼ãã¼ã®è¡¨ç¤ºã¨é表示ã«ä½¿ç¨ãã <input> ã¨ãããããªã¼ãã¼ã¨ãªã <div> ãå®ç¾©ãã¾ãã
ãã®å ´åãããã°ã©ã ã§è¡ãã®ã¨åæ§ã«ããã¿ã³ã«ã¯ HTML ã® popovertargetaction 屿§ãè¨å®ãã¾ãããã popover 屿§ã <div> ã«è¨å®ãããã¨ããªãã
<input id="toggleBtn" type="button" value="ããããªã¼ãã¼ã®è¡¨ç¤ºåãæ¿ã" />
<div id="mypopover">ããã¯ããããªã¼ãã¼ã®ã³ã³ãã³ãã§ãã</div>
JavaScript ã³ã¼ãã¯æåã« <div> 㨠<input> è¦ç´ ã®ãã³ãã«ãåå¾ãã¾ãã
ããã¦ãããããªã¼ãã¼ã«å¯¾å¿ãã¦ãããã©ããã調ã¹ã颿°ãå®ç¾©ãã¾ãã
const popover = document.getElementById("mypopover");
const toggleBtn = document.getElementById("toggleBtn");
// ããããªã¼ãã¼ API ã®å¯¾å¿ç¶æ³ã確èª
function supportsPopover() {
return HTMLElement.prototype.hasOwnProperty("popover");
}
ããããªã¼ãã¼ API ã«å¯¾å¿ãã¦ããå ´åãã³ã¼ã㯠<div> è¦ç´ ã® popover 屿§ã "auto" ã«è¨å®ããããããã°ã«ãã¿ã³ã®ããããªã¼ãã¼å¯¾è±¡ã¨ãã¾ãã
ããã¦ããã¿ã³ã® popoverTargetAction ã "toggle" ã«è¨å®ãã¾ãã
ããããªã¼ãã¼ API ã«å¯¾å¿ãã¦ããªãå ´åã¯ã <div> è¦ç´ ã®ããã¹ãã³ã³ãã³ãã夿´ãã¦ãã®ç¶æ
ã«ãããã°ã«ãã¿ã³ãé表示ã«ãã¾ãã
if (supportsPopover()) {
// <div> è¦ç´ ãèªåããããªã¼ãã¼ã«è¨å®
popover.popover = "auto";
// ãã¿ã³ãããããªã¼ãã¼ã®å¯¾è±¡ã«è¨å®
toggleBtn.popoverTargetElement = popover;
// ãã¿ã³ã§ããããªã¼ãã¼ã®è¡¨ç¤ºç¶æ
ãåãæ¿ããããã«è¨å®
toggleBtn.popoverTargetAction = "toggle";
} else {
popover.textContent = "ããããªã¼ãã¼ API ã«å¯¾å¿ãã¦ãã¾ããã";
toggleBtn.hidden = true;
}
ã¡ã¢: ããããªã¼ãã¼è¦ç´ ã¯æ¢å®ã§ã¯é表示ã§ããã API ã«å¯¾å¿ãã¦ããªãå ´åã¯ãé常éãã表示ããã¾ãã
ä¸è¨ã®ä¾ã試ãã¦ã¿ã¦ãã ããã ãã¿ã³ãåãæ¿ãããã¨ã§ããããªã¼ãã¼ã表示ãããããé表示ã«ãããã§ãã¾ãã ãèªåãããããªã¼ãã¼ã¯ãããããªã¼ãã¼ããã¹ãã®æ å¤ã鏿ãããã¨ã§è§£é¤ãããã¨ãã§ãã¾ãã
仿§æ¸
| Specification |
|---|
| HTML > # dom-popovertargetelement > |
ãã©ã¦ã¶ã¼ã®äºææ§
é¢é£æ å ±
popoverã°ãã¼ãã«å±æ§- ããããªã¼ãã¼ API