您好,我想知道如何在不同的圖像上動態加載模態。這是我目前的網頁。如何動態加載模態
假設當我點擊PI這個圖片的生命是彈出的模態。
我想與其他圖像發生同樣的事情。假設如果我點擊風箏衝浪者圖像,它會打開一個模式,左邊是風箏衝浪者圖像,右邊是文字。
這是我當前的代碼
$(document).ready(function() {
var $modal = $("#myModal");
$("#lifeofpi").click(function() {
$modal.show();
});
$modal.find('.close').click(function() {
$modal.hide();
});
});
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.7); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 700px;
height: 500px;
background-color: #101010;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modallifeofpi {
cursor: pointer;
height: 160px; // height
//width: 30%; // width
border: 5px solid white;
display: inline;
margin-top:0px;
position: absolute;
}
.modalheader {
color:white;
margin:0;
margin-left: 470px;
}
.modalheadertext {
color:white;
margin-left: 350px;
margin-top:40px;
}
.review-img {
cursor: pointer;
height: 160px; // height
//width: 30%; // width
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class='images'>
<img class="review-img" id="lifeofpi" src="https://images-na.ssl-images-amazon.com/images/I/51atapp7YTL._AC_US320_QL65_.jpg" alt="lifeofpi"></img>
<img class="review-img" id="kiterunner" src="https://images-na.ssl-images-amazon.com/images/I/51MtGFNeYjL._AC_US320_QL65_.jpg" alt="kiterunner"></img> </img>
<img class="review-img" id="starwars" src="https://images-na.ssl-images-amazon.com/images/I/51oqkfvEwZL._AC_US320_QL65_.jpg" alt="starwars"></img>
<img class="review-img" id="twilight" src="https://images-na.ssl-images-amazon.com/images/I/41K99+cInvL._AC_US320_QL65_.jpg" alt="twilight"></img>
</section>
<!-- The Modal -->
<div id="myModal" class="modal">
\t <!-- Modal content -->
\t <div class="modal-content">
\t \t <span class="close">×</span>
<img class="modallifeofpi" src="https://images-na.ssl-images-amazon.com/images/I/51atapp7YTL._AC_US320_QL65_.jpg" alt="lifeofpi"></img>
<h1 class="modalheader">Life of pi</h1>
<h2 class="modalheadertext">Published:</h2>
\t </div>
</div>
你忘了加上'jQuery'摘錄 – Rajesh
對不起,我不知道爲什麼片斷心不是工作它是如何出現在我的網頁。並且我在片段中添加了jquery – cars
您是否有一個外部源,您從中獲取模態信息,或者您只是將該信息與圖像一起放在頁面上? –