【发布时间】:2021-07-14 23:25:34
【问题描述】:
我想隐藏一个跨度,当另一个 Div onClick 事件出现时......
我没有使用JQuery。
代码在这里... https://jsfiddle.net/s24drt10/
我的 HTML:
<div class="outer">
<div onclick="showPopup('spanApasionados')" onfocusout="showPopup('spanApasionados')" class="apasionados popup">
<div class="inner">Apasionado
<span class="spanDown popuptext" id="spanApasionados">Bla Bla Con pasión</span>
</div>
</div>
</div>
<div class="outer">
<div onclick="showPopup('spanReferentes')" onfocusout="showPopup('spanReferentes')" class="referentes popup">
<div class="inner">Referente
<span class="spanDown popuptext" id="spanReferentes">Porque puedo hacer cosas bla bla.</span>
</div>
</div>
</div>
<div class="outer">
<div onclick="showPopup('spanProtectores')" onfocusout="showPopup('spanProtectores')" class="protectores popup">
<div class="inner">Protector
<span class="spanDown popuptext" id="spanProtectores">Protejo mi entorno bla, bla.</span>
</div>
</div>
</div>
<div class="outer">
<div onclick="showPopup('spanEjecutores')" onfocusout="showPopup('spanEjecutores')" class="ejecutores popup">
<div class="inner">Ejecutor
<span class="spanUp popuptext" id="spanEjecutores">Siepr ejecutando bla, blah.</span>
</div>
</div>
</div>
<div class="outer">
<div onclick="showPopup('spanCocreadores')" onfocusout="showPopup('spanCocreadores')" class="cocreadores popup">
<div class="inner">Cocreador
<span class="spanUp popuptext" id="spanCocreadores">Concreando, bla, bla....</span>
</div>
</div>
</div>
我的 CSS
/* Popup container - can be anything you want */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* The actual popup */
.popup .popuptext {
visibility: hidden;
width: 40vh;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding-top: 10px;
padding-right: 5px;
padding-bottom: 10px;
padding-left: 5px;
position: absolute;
z-index: 99 !important;
left: 7.5vh;
right: 70px;
margin-left: -10vh;
}
/* Popup arrow uptriangle*/
.inner .spanDown::before {
content: "";
position: absolute;
top: -10px;
left: 50%;
margin-left: -5px;
margin-right: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #555 transparent;
}
/* Popup arrow downtriangle*/
.inner .spanUp::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
.inner .spanDown {
top: 61px;
}
.inner .spanUp {
bottom: 60px;
}
/* Toggle this class - hide and show the popup */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}
.popup .hide {
visibility: hidden;
-webkit-animation: fadeOut 1s;
animation: fadeOut 1s;
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
div.apasionados {
background-image: url(https://thumbs.dreamstime.com/b/cyan-texture-background-space-your-text-use-as-wallpaper-poster-banner-designs-cyan-texture-background-172346179.jpg);
color: white !important;
border: none;
width: 309px;
height: 69px;
background-size: cover;
font-family: Gotham Book !important;
font-weight: normal !important;
font-style: normal;
text-shadow: none;
box-shadow: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 0px;
border-left: 0px;
border-right: 0px;
position: relative;
display: flex;
align-items: center;
}
div.referentes {
background-image: url(https://thumbs.dreamstime.com/b/cyan-texture-background-space-your-text-use-as-wallpaper-poster-banner-designs-cyan-texture-background-172346179.jpg);
color: white !important;
border: none;
width: 309px;
height: 69px;
background-size: cover;
font-family: Gotham Book !important;
font-weight: normal !important;
font-style: normal;
text-shadow: none;
box-shadow: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 0px;
border-left: 0px;
border-right: 0px;
position: relative;
display: flex;
align-items: center;
}
div.protectores {
background-image: url(https://thumbs.dreamstime.com/b/cyan-texture-background-space-your-text-use-as-wallpaper-poster-banner-designs-cyan-texture-background-172346179.jpg);
color: white !important;
border: none;
width: 309px;
height: 69px;
background-size: cover;
font-family: Gotham Book !important;
font-weight: normal !important;
font-style: normal;
text-shadow: none;
box-shadow: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 0px;
border-left: 0px;
border-right: 0px;
position: relative;
display: flex;
align-items: center;
}
div.ejecutores {
background-image: url(https://thumbs.dreamstime.com/b/cyan-texture-background-space-your-text-use-as-wallpaper-poster-banner-designs-cyan-texture-background-172346179.jpg);
color: white !important;
border: none;
width: 309px;
height: 69px;
background-size: cover;
font-family: Gotham Book !important;
font-weight: normal !important;
font-style: normal;
text-shadow: none;
box-shadow: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 0px;
border-left: 0px;
border-right: 0px;
position: relative;
display: flex;
align-items: center;
}
div.cocreadores {
background-image: url(https://thumbs.dreamstime.com/b/cyan-texture-background-space-your-text-use-as-wallpaper-poster-banner-designs-cyan-texture-background-172346179.jpg);
color: white !important;
border: none;
width: 309px;
height: 69px;
background-size: cover;
font-family: Gotham Book !important;
font-weight: normal !important;
font-style: normal;
text-shadow: none;
box-shadow: none;
margin-left: 0px;
margin-right: 0px;
padding-left: 20px;
padding-right: 0px;
border-left: 0px;
border-right: 0px;
position: relative;
display: flex;
align-items: center;
}
我的 Javascript 代码
// When the user clicks on div, show the popup
function showPopup(id) {
var popup = document.getElementById(id);
popup.classList.toggle("show");
}
// When the user clicks on div, hide the popup
function hidePopup(id) {
var popup = document.getElementById(id);
popup.classList.toggle("hide");
}
但是,我的代码不起作用...
我首先使用onfocusout="hidePopup('spanXXXXXX') 进行测试,但无法正常工作....
- 如何解决?
- 我需要使用其他事件吗?
【问题讨论】:
-
您好,看看我的回答能否解决您的问题!
标签: javascript html css popup show-hide