我想在點擊放在網頁上的圖像時顯示一個簡單的彈出窗口。點擊圖片時我看不到彈出窗口。任何人都可以幫我理清這個問題嗎?以下是代碼,我現在所擁有的:單擊圖像後如何顯示彈出框
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
.popup {
position: relative;
display: inline-block;
cursor: pointer;
}
.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;
}
\t \t
\t \t .popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s
}
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popup" onclick="myFunction()" style="width: 1000px; height: 600px;">
\t \t <img src="Boma_1_2/F16_20170316141116392_0001.jpg" alt="Boma" style="width:1000px;height:600px;">
\t \t <span class="popuptext" id="myPopup">Popup text...</span>
</div>
爲什麼你在使用'底部:125%;'?順便說一句,你沒有'body'標籤。 – Huelfe
我刪除了底部:125%,現在我看到了彈出窗口,但現在它只是顯示在頂部,無論我點擊圖像的位置。我希望彈出窗口顯示在點擊附近。你能告訴我我該怎麼做? – Salman
STYLE標籤應嵌套在HEAD標籤中,且您的代碼應具有BODY標籤 – NoOorZ24