rebekkab20850564 wrote I am experiencing a similar situation. I have an imagemap in which I want to open 5 different modals. Until now I could only manage to open the same modal on several areas. How can I connect a new modal to another area in the image? Can somebody help me here? |
You can use the one image and put some 'anchor' tag hotspots positioned over the image.
Normally I would not use multiple modals, I would use just the 1 modal and populate it with information either from a database or a javascript array of data but I think the below is going to be simpler to understand:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HotSpot</title>
<style>
body {
font-family: helvetica, sans-serif;
font-size: 14px;
line-height: 17px;
}
* {
box-sizing: border-box;
}
h1 {
text-align: center;
margin: 0;
padding: 50px 0 30px 0;
}
.product {
position: relative;
width: 95%;
margin: 0 auto;
}
@media screen and (max-width: 768px) {
.product {
width: 100%;
}
}
.product img {
max-width: 100%;
}
.hotspot {
position: absolute;
display: inline-block;
background-color: red;
color: #fff;
text-decoration: none;
padding: 10px 15px;
border-radius: 50%;
}
.hotspot:hover {
background-color: #666;
}
@media screen and (max-width: 768px) {
.hotspot {
padding: 5px 10px;
}
}
.spot_1 {
top: 60%;
left: 23%;
}
.spot_2 {
top: 50%;
left: 42%;
}
.spot_3 {
top: 30%;
left: 55%;
}
.spot_4 {
top: 20%;
left: 70%;
}
.spot_5 {
top: 55%;
left: 60%;
}
.modal {
position: absolute;
top: 50%;
transform: translateY(-50%);
background-color: #fff;
display: none;
box-shadow: 2px 2px 9px 4px rgba(0, 0, 0, 0.2);
width: 40%;
margin: 0 30%;
color: #000;
}
.modal h3 {
margin: 0;
padding: 10px 0;
}
.modal p {
margin: 0;
padding: 0 0 5px 0;
}
.modal_info {
padding: 15px;
}
.modal_info a{
position: absolute;
top: -28px;
right: 0;
display: inline-block;
text-decoration: none;
background-color: #000;
color: #fff;
padding: 7px 10px 4px 10px;
}
@media screen and (max-width: 768px) {
.modal_1, .modal_2, .modal_3, .modal_4, .modal_5 {
top: 0;
margin: 0 5%;
transform: translateY(0);
width: 90%;
}
}
</style>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$('.product a').css('cursor' , 'pointer').click(function(){
$('.modal').fadeOut();
var modal = $(this).attr('data-modal');
if($(modal).is(':visible') == true) {
$(modal).fadeOut();
}
else {
$(modal).fadeIn();
}
});
});
</script>
</head>
<body>
<h1>Product Diagram</h1>
<div class="product">
<a href="#" class="hotspot spot_1" data-modal=".modal_1">+</a>
<a href="#" class="hotspot spot_2" data-modal=".modal_2">+</a>
<a href="#" class="hotspot spot_3" data-modal=".modal_3">+</a>
<a href="#" class="hotspot spot_4" data-modal=".modal_4">+</a>
<a href="#" class="hotspot spot_5" data-modal=".modal_5">+</a>
<img src="https://images.unsplash.com/photo-1549480017-d76466a4b7e8" alt="Tiger">
<div class="modal modal_1">
<div class="modal_info">
<img src="https://images.unsplash.com/photo-1553054366-ebbf4296eb32" alt="Tiger">
<h3>Modal 1</h3>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<a href="#">X</a>
</div>
<!-- end modal info -->
</div>
<!-- end modal_1 -->
<div class="modal modal_2">
<div class="modal_info">
<img src="https://images.unsplash.com/photo-1557973254-3b9af1ee03aa" alt="Tiger">
<h3>Modal 2</h3>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<a href="#">X</a>
</div>
<!-- end modal info -->
</div>
<!-- end modal_2 -->
<div class="modal modal_3">
<div class="modal_info">
<img src="https://images.unsplash.com/photo-1545462616-efed1939219f" alt="Tiger">
<h3>Modal 3</h3>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<a href="#">X</a>
</div>
<!-- end modal info -->
</div>
<!-- end modal_3 -->
<div class="modal modal_4">
<div class="modal_info">
<img src="https://images.unsplash.com/photo-1494979362559-7f9efdc9b88c" alt="Tiger">
<h3>Modal 4</h3>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<a href="#">X</a>
</div>
<!-- end modal info -->
</div>
<!-- end modal_4 -->
<div class="modal modal_5">
<div class="modal_info">
<img src="https://images.unsplash.com/photo-1477764250597-dffe9f601ae8" alt="Tiger">
<h3>Modal 5</h3>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<p>Some text goes here. Some text goes here. Some text goes here. Some text goes here.</p>
<a href="#">X</a>
</div>
<!-- end modal info -->
</div>
<!-- end modal_5 -->
</div>
<!-- end product -->
</body>
</html>