gpt4 book ai didi

javascript - 图像未在弹出窗口中显示(CSS、HTML、Javascript)

转载 作者:行者123 更新时间:2023-11-28 02:25:17 24 4
gpt4 key购买 nike

目前,我正在构建一个网站,但遇到了一个问题。我对 CSS、HTML、Javascript 的世界相当陌生,所以也许这对你们大多数人来说都是轻而易举的事,但我面临以下问题。我想在弹出窗口中显示一张图片,但是图片没有显示(在代码片段中称为“ErrorImage”)。我检查了图像的文件路径是否正确,是的。请查看下面的片段。有帮助吗?

// When the user clicks on div, open the popup
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
/* 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: 500px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 10px;
position: absolute;
z-index: 1;
bottom: 60px;
left: -50%;
right: -50%;
margin-left: -80px;
opacity: 0.98;
text-align: justify;
}

/* Toggle this class - hide and show the popup */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 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 class="popup" onclick="myFunction()">
<a title="More about us">
<img src="About.JPG" alt="About">
</a>
<span class="popuptext" id="myPopup"><img src="ErrorImage.JPG"<
<p>Example text</p>
</span>
</div>

最佳答案

它正在显示,但您的左边是 -50%,这就是它超出屏幕的原因。我已经相应地调整了它,所以它显示在屏幕上。希望这可以帮助。谢谢

// When the user clicks on div, open the popup
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
/* 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: 500px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 10px;
position: absolute;
z-index: 1;
bottom: 0;
left: 0;
right: 0;
margin-left: 0;
opacity: 0.98;
text-align: justify;
top: 100px;
height: 40px;
}

/* Toggle this class - hide and show the popup */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 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 class="popup" onclick="myFunction()">
<a title="More about us">
about
</a>
<span class="popuptext" id="myPopup"><p>Example text</p></span>
</div>

关于javascript - 图像未在弹出窗口中显示(CSS、HTML、Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54514652/

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