私のウェブサイトには、と表示され、トリガーがクリックされたトラックの上に&のコメントというモーダルが表示されます。ユーザーがモーダルトリガーをクリックしたときにモーダルが開かない
しかし、トラックが手続き的にのPHPに表示されるため、私はそれを奇妙な方法で設定しなければなりませんでした。
これは私の簡略マークアップ:このマークアップは、(データベース内の各トラックを表すために)ページ間で複製される
<div class="f-wave-send">
<div class="t__trigger-actions"> <!-- this is the modal trigger button !-->
<span id="trigger-actions-modal"></span>
</div>
<div class="f-track__actions" id="track-actions"> <!-- this is the modal !-->
<div class="close-actions"> <!-- this is the close button !-->
<span></span>
</div>
<div class="f-track-actions-inner">
<!-- modal contents !-->
</div>
</div>
</div>
。 に似ています。さんのフィード。
これは、すべてのモーダルの機能を制御JSです:
$(".t__trigger-actions").click(function(){ // when one of the modal triggers is clicked
var parent = $(this).parent();
parent.find(".f-track__actions").css("display", "block"); // get the modal within ONLY the same container to display
parent.addClass("modal__open"); // and add the class modal__open to the container
});
$(".close-actions").click(function(){ // when the close button is clicked
$(".modal__open").children(".f-track__actions").css("display", "none"); // hide the modal
$(".f-wave-send").removeClass("modal__open"); // remove the modal__open class from the container
});
$(document).bind('click', function(e) { // if user clicks on anything but the main container
if(!$(e.target).is('.modal__open')) {
$(".modal__open").children(".f-track__actions").css("display", "none"); // hide the modal
$(".f-wave-send").removeClass("modal__open"); // remove the modal__open class from the container
}
});
私は何が起こっているかを説明しようと、可能な場合はコメントしています。しかしここでもう一度説明します。
多くモーダルの1をユーザーがクリックするとdocument
内トリガー
modal__open
だクラス親コンテナを追加)します。
ユーザが同じモーダルその閉じる閉じるボタン(または文書に)をクリックした場合。
私は今、そのすべてのヘルプ(や提案が)高く評価されながら、少しのためにこれを理解しようとして立ち往生してきました。
ありがとうございました。
EDIT:
私は起こるしたい何がモーダルが開いたときに、ユーザーがモーダルのうち、OR [閉じる]ボタンをクリックしたとき(つまり、理にかなっている場合)、それだけで閉じ、です。
だから、問題は何ですか? – Pointy
@モーダルは開いていませんか?私はかなりタイトルを指定したと確信しています –
私はモーダルが開いているが、すぐに再び閉じていると推測する危険があります。その最終的なバインドを削除して何が起こるのか見てみましょうか? – DavidG