前提
質問者は素人です。
専門用語の使い方が間違っている可能性があります。
何卒お許しください。
実現したいこと
imgをクリックするとmp4コンテンツをポップアップ表示するJsを作成しました。
htmlに対象のクラス(.popup)が1つであれば問題ありませんが、2つ以上になると最後のmp4コンテンツがポップアップされてしまいます。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
html
1<div id="contents"> 2<div id="main"> 3<div id="mainInr"> 4<h1 class="head01">設備紹介</h1> 5<div class="basicFlt"> 6<ul class="fltList clm3"> 7<li><p class="pink bold center size18">a</p> 8<img class="popupBtn" src="images/facility01.jpg" alt="" onmouseover="this.src='images/facility01_1.png'" onmouseout="this.src='images/facility01.jpg'"> 9 <div class="popup"> 10 <video playsinline muted autoplay src="images/facility01.mp4" loop class="popup-content"></video> 11 <div class="btn-close">閉じる</div> 12 </div> 13<p>説明文</p> 14</li> 15… 16<li><p class="pink bold center size18">b</p> 17<img class="popupBtn" src="images/facility10.jpg" alt="" onmouseover="this.src='images/facility10_1.png'" onmouseout="this.src='images/facility10.jpg'"> 18 <div class="popup"> 19 <video playsinline muted autoplay src="images/facility10.mp4" loop class="popup-content"></video> 20 <div class="btn-close">閉じる</div> 21 </div> 22<p>説明文</p> 23</li> 24</ul> 25</div>
css
1@charset "UTF-8"; 2/* CSS Document */ 3 4#mv { 5 background: url(/about/images/mv.png) center top no-repeat !important; 6} 7 8 9 10.head01{ 11 overflow: hidden; 12} 13 14.head01 p.year{ 15 float: left; 16 margin-left:40%; 17 font-size: 1em !important; 18} 19 20.head01 p.day{ 21 float: right; 22 margin-top: 20px; 23 font-size: 12px; 24} 25 26 27 28 29@media only screen and (max-width: 750px) { 30 31.head01 p.year{ 32 /* float: left; */ 33 font-size: 1em !important; 34 margin-left:0px; 35} 36 37.head01 p.day{ 38 float: right; 39 margin-top: 0px; 40} 41 42 43} 44 45/* 全体設定 */ 46* { 47 box-sizing: border-box; 48} 49 50.popupBtn{ 51 cursor: pointer; 52} 53 54 /* ポップアップウインドウの設定 */ 55.popup { 56 background-color: rgba(0,0,0,.7); 57 display: none; 58 position:fixed; 59 top: 0; 60 left: 0; 61 /*right: 0; 62 bottom: 0; 63 margin: 0 auto;*/ 64 width: 100%; 65 height: 100%; 66 /*overflow-y: auto;*/ 67 } 68 69.popup-content{ 70 /*background: #fff; 71 padding: 30px; 72 height: 80%;*/ 73 width: 80%; 74 display: flex; 75 justify-content: center; 76 align-items: center; 77} 78 79.flex{ 80 display: flex; 81 justify-content: center; 82 align-items: center; 83 flex-wrap: wrap; 84} 85 86 /* 閉じるボタン */ 87.btn-close{ 88 background: #000; 89 border-radius: 10px; 90 color: #E7656D; 91 padding: 10px; 92 margin: 10px; 93 width: 80%; 94 text-align: center; 95 cursor: pointer; 96} 97 98 99 @media only screen and (max-width: 750px){ 100 video { max-width: 100%; } 101}
js
1$(document).on("click", ".popupBtn", function() {//$("要素").click だとjsを読み込んだ時点で"要素"が存在しない為NG 2 $(".popup") 3 .addClass("flex") 4}); 5 6$(document).on("click", ".btn-close", function() { 7 $(".popup") 8 .removeClass("flex") 9 //.fadeOut(); 10}); 11
試したこと
$(".popup")ではpopupBtnと同じ要素内の.popupと指定できていない事が原因と考えてみましたが上手くいきませんでした。
何卒よろしくお願い致します。
js
1$(document).on("click", ".popupBtn", function(getElementByclass) {//$("要素").click だとjsを読み込んだ時点で"要素"が存在しない為NG 2 let pop = $(".popupBtn").children(".popup"); 3 //$(".popup") 4 pop.addClass("flex") 5});
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/19 03:20
2022/07/19 08:52