{"id":5972,"date":"2024-09-27T16:14:34","date_gmt":"2024-09-27T07:14:34","guid":{"rendered":"https:\/\/code-plus.jp\/gp\/?p=5972"},"modified":"2026-01-08T11:13:52","modified_gmt":"2026-01-08T02:13:52","slug":"post-5972","status":"publish","type":"post","link":"https:\/\/code-plus.jp\/gp\/post-5972\/","title":{"rendered":"dialog\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30fc\u30c0\u30eb\u306e\u5b9f\u88c5\u65b9\u6cd5"},"content":{"rendered":"<h2 class=\"wp-block-heading\">\u306f\u3058\u3081\u306b<\/h2>\r\n<p>Web\u30b5\u30a4\u30c8\u3084\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3088\u304f\u4f7f\u7528\u3055\u308c\u308bUI\u30d1\u30bf\u30fc\u30f3\u306e\u4e00\u3064\u306b\u300c\u30e2\u30fc\u30c0\u30eb\u300d\u304c\u3042\u308a\u307e\u3059\u3002\u30e2\u30fc\u30c0\u30eb\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u6ce8\u610f\u3092\u7279\u5b9a\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u306b\u96c6\u4e2d\u3055\u305b\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u308b\u91cd\u8981\u306aUI\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u3059\u3002<\/p>\r\n<p>\u4eca\u56de\u306f\u3001HTML5\u3067\u5c0e\u5165\u3055\u308c\u305f<code>&lt;dialog&gt;<\/code>\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u3066\u3001\u30b7\u30f3\u30d7\u30eb\u304b\u3064\u52b9\u679c\u7684\u306a\u30e2\u30fc\u30c0\u30eb\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\r\n\r\n<iframe height=\"300\" style=\"width: 100%;\" scrolling=\"no\" title=\"\u3010PHP\u3011modal-dialog.php\uff08dialog\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30fc\u30c0\u30eb\uff09\" src=\"https:\/\/codepen.io\/sarap422\/embed\/gOZMeLY?default-tab=js\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\">\r\n  See the Pen <a href=\"https:\/\/codepen.io\/sarap422\/pen\/gOZMeLY\">\r\n  \u3010PHP\u3011modal-dialog.php\uff08dialog\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u30e2\u30fc\u30c0\u30eb\uff09<\/a> by sarap422 (<a href=\"https:\/\/codepen.io\/sarap422\">@sarap422<\/a>)\r\n  on <a href=\"https:\/\/codepen.io\">CodePen<\/a>.\r\n<\/iframe>\r\n\r\n<h2 class=\"wp-block-heading\">HTML\u306e\u69cb\u9020<\/h2>\r\n<p>\u307e\u305a\u3001\u30e2\u30fc\u30c0\u30eb\u306eHTML\u306e\u69cb\u9020\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\r\n\r\n<pre class=\"language-html\"><code>\r\n&lt;dialog id=\"mdl-pejiVKU1\" class=\"modal-container modal-viewDialog\"&gt;\r\n  &lt;ul class=\"modal-wrapper\"&gt;\r\n    &lt;li class=\"modal-slide\"&gt;\r\n      &lt;a class=\"modal-ifield\"&gt;\r\n        &lt;picture class=\"modal-thumbnail\"&gt;\r\n          &lt;img src=\"\u753b\u50cf\u306eURL\" alt=\"\"&gt;\r\n        &lt;\/picture&gt;\r\n        &lt;div class=\"modal-caption\"&gt;\r\n          &lt;h4 class=\"modal-title\"&gt;Image:01&lt;\/h4&gt;\r\n        &lt;\/div&gt;\r\n      &lt;\/a&gt;\r\n    &lt;\/li&gt;\r\n  &lt;\/ul&gt;\r\n  &lt;a class=\"modal-closer js-clsrVKUA\" aria-label=\"\u9589\u3058\u308b\"&gt;\u00d7&lt;\/a&gt;\r\n&lt;\/dialog&gt;\r\n<\/code><\/pre>\r\n\r\n<p>\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\r\n<ul class=\"wp-block-list\">\r\n  <li><code>&lt;dialog&gt;<\/code>\u30bf\u30b0\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u30e2\u30fc\u30c0\u30eb\u6a5f\u80fd\u3092\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/li>\r\n  <li>\u5404\u30e2\u30fc\u30c0\u30eb\u306b\u4e00\u610f\u306eID\u3092\u4ed8\u4e0e\u3057\u307e\u3059\uff08\u4f8b\uff1a<code>id=\"mdl-pejiVKU1\"<\/code>\uff09\u3002<\/li>\r\n  <li>\u30e2\u30fc\u30c0\u30eb\u3092\u9589\u3058\u308b\u30dc\u30bf\u30f3\u306b\u306f\u7279\u5b9a\u306e\u30af\u30e9\u30b9\uff08<code>js-clsrVKUA<\/code>\uff09\u3092\u4ed8\u4e0e\u3057\u3001JavaScript\u304b\u3089\u64cd\u4f5c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n\r\n<h2 class=\"wp-block-heading\">JavaScript\u306e\u5b9f\u88c5<\/h2>\r\n<p>\u6b21\u306b\u3001\u30e2\u30fc\u30c0\u30eb\u3092\u5236\u5fa1\u3059\u308bJavaScript\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\r\n\r\n<pre class=\"language-javascript\"><code>\r\n(function () {\r\n  const mdalOpnrs = Array.from(document.querySelectorAll(\".js-opnrVKUA\"));\r\n  const mdalClsrs = Array.from(document.querySelectorAll(\".js-clsrVKUA\"));\r\n  const { body } = document;\r\n\r\n  function openModal(modalId) {\r\n    const modal = document.getElementById(modalId);\r\n    if (modal) {\r\n      modal.showModal();\r\n      modal.classList.add('is-opened');\r\n      body.classList.add('is-modaled');\r\n    }\r\n  }\r\n\r\n  function closeModal(modal) {\r\n    modal.close();\r\n    modal.classList.remove('is-opened');\r\n    body.classList.remove('is-modaled');\r\n    mdalOpnrs.forEach(mdalOpnr => mdalOpnr.classList.remove('is-pressed'));\r\n  }\r\n\r\n  mdalOpnrs.forEach(mdalOpnr => {\r\n    mdalOpnr.addEventListener('click', function (e) {\r\n      e.preventDefault();\r\n      const modalId = this.getAttribute('data-opento');\r\n      openModal(modalId);\r\n      this.classList.add('is-pressed');\r\n    });\r\n  });\r\n\r\n  mdalClsrs.forEach(mdalClsr => {\r\n    mdalClsr.addEventListener('click', function (e) {\r\n      e.preventDefault();\r\n      const modal = this.closest('dialog');\r\n      closeModal(modal);\r\n    });\r\n  });\r\n\r\n  document.querySelectorAll('dialog').forEach(modal => {\r\n    modal.addEventListener('cancel', function () {\r\n      closeModal(this);\r\n    });\r\n  });\r\n})();\r\n<\/code><\/pre>\r\n\r\n<p>\u4e3b\u306a\u6a5f\u80fd\uff1a<\/p>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u30e2\u30fc\u30c0\u30eb\u3092\u958b\u304f<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li><code>openModal<\/code>\u95a2\u6570\u306f\u3001\u6307\u5b9a\u3055\u308c\u305fID\u306e\u30e2\u30fc\u30c0\u30eb\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/li>\r\n  <li><code>showModal()<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001dialog\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/li>\r\n  <li>\u30e2\u30fc\u30c0\u30eb\u3068<code>body<\/code>\u8981\u7d20\u306b\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30b9\u30bf\u30a4\u30ea\u30f3\u30b0\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u30e2\u30fc\u30c0\u30eb\u3092\u9589\u3058\u308b<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li><code>closeModal<\/code>\u95a2\u6570\u306f\u3001\u30e2\u30fc\u30c0\u30eb\u3092\u9589\u3058\u3001\u95a2\u9023\u3059\u308b\u30af\u30e9\u30b9\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/li>\r\n  <li><code>close()<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001dialog\u3092\u9589\u3058\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u306e\u8a2d\u5b9a<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li>\u30e2\u30fc\u30c0\u30eb\u3092\u958b\u304f\u30dc\u30bf\u30f3\uff08<code>.js-opnrVKUA<\/code>\uff09\u306b\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/li>\r\n  <li>\u30e2\u30fc\u30c0\u30eb\u3092\u9589\u3058\u308b\u30dc\u30bf\u30f3\uff08<code>.js-clsrVKUA<\/code>\uff09\u306b\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/li>\r\n  <li><code>cancel<\/code>\u30a4\u30d9\u30f3\u30c8\u3092\u30ea\u30c3\u30b9\u30f3\u3057\u3066\u3001Esc\u30ad\u30fc\u3067\u306e\u30e2\u30fc\u30c0\u30eb\u9589\u9396\u306b\u5bfe\u5fdc\u3057\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<h2 class=\"wp-block-heading\">\u5b9f\u88c5\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u30a2\u30af\u30bb\u30b7\u30d3\u30ea\u30c6\u30a3<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li><code>&lt;dialog&gt;<\/code>\u30bf\u30b0\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30b9\u30af\u30ea\u30fc\u30f3\u30ea\u30fc\u30c0\u30fc\u3068\u306e\u4e92\u63db\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/li>\r\n  <li>\u9589\u3058\u308b\u30dc\u30bf\u30f3\u306b\u306f<code>aria-label<\/code>\u5c5e\u6027\u3092\u4f7f\u7528\u3057\u3066\u3001\u305d\u306e\u76ee\u7684\u3092\u660e\u78ba\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u67d4\u8edf\u6027<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li><code>data-opento<\/code>\u5c5e\u6027\u3092\u4f7f\u7528\u3057\u3066\u3001\u958b\u304f\u3079\u304d\u30e2\u30fc\u30c0\u30eb\u306eID\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u8907\u6570\u306e\u30e2\u30fc\u30c0\u30eb\u3092\u7c21\u5358\u306b\u7ba1\u7406\u3067\u304d\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li>\u30a4\u30d9\u30f3\u30c8\u30c7\u30ea\u30b2\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u305b\u305a\u3001\u5fc5\u8981\u306a\u8981\u7d20\u306b\u306e\u307f\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u4e0d\u8981\u306a\u30a4\u30d9\u30f3\u30c8\u51e6\u7406\u3092\u6e1b\u3089\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<ol class=\"wp-block-list\">\r\n  <li><strong>\u30b9\u30bf\u30a4\u30ea\u30f3\u30b0\u306e\u5bb9\u6613\u3055<\/strong>\uff1a<\/li>\r\n<\/ol>\r\n<ul class=\"wp-block-list\">\r\n  <li>\u30e2\u30fc\u30c0\u30eb\u306e\u72b6\u614b\u306b\u5fdc\u3058\u3066\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\/\u524a\u9664\u3059\u308b\u3053\u3068\u3067\u3001CSS\u3067\u306e\u67d4\u8edf\u306a\u30b9\u30bf\u30a4\u30ea\u30f3\u30b0\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\r\n<\/ul>\r\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\r\n<p><code>&lt;dialog&gt;<\/code>\u30bf\u30b0\u3092\u4f7f\u7528\u3057\u305f\u30e2\u30fc\u30c0\u30eb\u306e\u5b9f\u88c5\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u3067\u3042\u308a\u306a\u304c\u3089\u5f37\u529b\u3067\u3059\u3002\u30d6\u30e9\u30a6\u30b6\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u6a5f\u80fd\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30a2\u30af\u30bb\u30b7\u30d3\u30ea\u30c6\u30a3\u3068\u6027\u80fd\u306e\u4e21\u9762\u3067\u512a\u308c\u305fUI\u3092\u63d0\u4f9b\u3067\u304d\u307e\u3059\u3002<\/p>\r\n<p>\u3053\u306e\u5b9f\u88c5\u3092\u30d9\u30fc\u30b9\u306b\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u8981\u4ef6\u306b\u5fdc\u3058\u3066\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u3053\u3068\u3067\u3001\u69d8\u3005\u306a\u30cb\u30fc\u30ba\u306b\u5bfe\u5fdc\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>","protected":false},"excerpt":{"rendered":"\u306f\u3058\u3081\u306b Web\u30b5\u30a4\u30c8\u3084\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3088\u304f\u4f7f\u7528\u3055\u308c\u308bUI\u30d1\u30bf\u30fc\u30f3\u306e\u4e00\u3064\u306b\u300c\u30e2\u30fc\u30c0\u30eb\u300d\u304c\u3042\u308a\u307e\u3059\u3002\u30e2\u30fc\u30c0\u30eb\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u6ce8\u610f\u3092\u7279\u5b9a\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u306b\u96c6\u4e2d\u3055\u305b\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u308b\u91cd\u8981\u306aUI\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u3059\u3002 \u4eca\u56de\u306f\u3001HTML[...]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[287,286,233,180,113,114],"class_list":{"0":"post-5972","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-javascript","7":"tag-287","8":"tag-dialog","9":"tag-ui","10":"tag-html","11":"tag-javascript","12":"tag-114"},"_links":{"self":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/5972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/comments?post=5972"}],"version-history":[{"count":1,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/5972\/revisions"}],"predecessor-version":[{"id":8766,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/5972\/revisions\/8766"}],"wp:attachment":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media?parent=5972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/categories?post=5972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/tags?post=5972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}