gpt4 book ai didi

html - 如果您打开另一个弹出窗口,请关闭打开的弹出窗口

转载 作者:行者123 更新时间:2023-11-28 01:14:20 25 4
gpt4 key购买 nike

嘿,我制作了几个弹出窗口。按打开的弹出窗口关闭弹出窗口。我想做的是,如果您打开一个新的弹出窗口,那么另一个出现的弹出窗口将关闭。

For example if I open a pop up 1. then I open the pop up 2, then when the pop up 2 opens the pop up 1 is closed

这是我的html代码

<body style="text-align:center">
<br><br><br>
<div class="popup" onclick="popUp1()">Click me!
<span class="popuptext" id="myPopup1">Popup 1</span>
</div>
&nbsp; &nbsp; &nbsp;
<div class="popup" onclick="popUp2()">Click me!
<span class="popuptext" id="myPopup2">Popup 2</span>
</div>

&nbsp; &nbsp; &nbsp;
<div class="popup" onclick="popUp3()">Click me!
<span class="popuptext" id="myPopup3">Popup 3</span>
</div>

<script>
function popUp1() {
var popup = document.getElementById("myPopup1");
popup.classList.toggle("show");
}

function popUp2() {
var popup = document.getElementById("myPopup2");
popup.classList.toggle("show");
}

function popUp3() {
var popup = document.getElementById("myPopup3");
popup.classList.toggle("show");
}
</script>

</body>

这是我的CSS

.popup {
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
-moz-animation: fadeIn 1s;
-ms-animation: fadeIn 1s;
animation: fadeIn 1s;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity:1 ; }
}

谢谢

最佳答案

您需要一个 JavaScript 函数来执行此操作,如下所示:

 $('.popup').on('click', function() {
$('.popup').each(function(i, elem){
if ($(elem).hasClass('show') && this !== elem ) {
$(elem).removeClass('show');
}
});
});

关于html - 如果您打开另一个弹出窗口,请关闭打开的弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51944150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com