Related
Why is the image not changing on hover? The image should change on hover and onclick and use the same image map
<script>
function changeImage() {
document.getElementById('image').src = document.getElementById('some_id').getAttribute('data-img-src');
};
</script>
<html>
<body>
<img id="image" src="http://imgur.com/SY5h8EC" map="#map" />
<map name="map">
<map id="some_id" data-img-src='http://imgur.com/Sch9YFq'>
<area shape="poly" coords="172,227,181,224,183,213,189,201,195,193,199,190,199,184,126,93,135,93,123,79,103,96,84,117,68,140,58,162,51,186,48,201,47,214,135,219,130,227,148,227,147,225,151,227,149,223,153,227,153,221,156,225,157,214,160,202,166,190,174,179,176,177,174,174,191,176,192,192,189,189,180,200,174,212,172,224,172,227" width="453" height="453" id="area1"
onmouseover=" changeImage();"/>
</map>
</map>
</body>
</html>
I changed the image links and wrote the code into a jsFiddle, you also had to change "map" to "usemap" and I got rid of one of the maps, I dont think you need it:
<body>
<img id="image" src="http://i.imgur.com/SY5h8EC.png" usemap="#map" />
<map name="map" id="some_id" data-img-src='http://i.imgur.com/Sch9YFq.png'>
<area shape="poly" coords="172,227,181,224,183,213,189,201,195,193,199,190,199,184,126,93,135,93,123,79,103,96,84,117,68,140,58,162,51,186,48,201,47,214,135,219,130,227,148,227,147,225,151,227,149,223,153,227,153,221,156,225,157,214,160,202,166,190,174,179,176,177,174,174,191,176,192,192,189,189,180,200,174,212,172,224,172,227" id="area1" onmouseover=" changeImage();" />
</map>
</body>
<script>
function changeImage() { document.getElementById('image').src=document.getElementById('some_id').getAttribute('data-img-src');
}
</script>
Working Fiddle:
https://jsfiddle.net/3eqb4uuj/
If you need help with something else please comment and I'll edit it
I have used Image Mapping to specify which image to display if a user clicks on a particular area on the image. Here is my code:
<html>
<body>
<div align="center">
<img id="IMGMAPS" src="base.jpg" border="0" width="802" height="1026" orgWidth="802" orgHeight="1026" usemap="#image-maps" alt="" />
<map name="image-maps" id="IMGMAPS">
<area shape="rect" coords="800,1024,802,1026" alt="Image Map" style="outline:none;" title="Image Map" href="base.jpg" />
<area alt="" title="" href="abc\1.jpg" shape="poly" coords="248,177,365,177,364,257,248,256" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\2.jpg" shape="poly" coords="386,193,501,180,510,258,394,271" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\3.jpg" shape="poly" coords="539,221,650,250,631,327,518,299" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\4.jpg" shape="poly" coords="128,277,222,271,228,369,135,375" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\5.jpg" shape="poly" coords="238,281,352,265,360,325,359,342,250,359" style="outline:none;" target="_self" />
</map>
</div>
</body>
</html>
This code results in the following image:
What I want is images 1, 2, 3, 4, 5 should open in a popup in the same window if a user clicks on the co-ordinates specified.
How do I achieve this?
Edit 1:
image
The base image is a single image. 1, 2, 3, 4, 5 are the areas with specific co-ordinates on the image. Each area has a corresponding image which opens in a popup only when a user clicks on a particular area with specific co-ordinates.
Edit 2: As suggested by #Edrees, I have made the following changes:
Added Foundation JS
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.js" ></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.min.js" ></script>
<script>
$(document).foundation();
</script>
Used data-reveal-id
<img id="IMGMAPS" src="selfie.jpg" border="0" width="802" height="1026" orgWidth="802" orgHeight="1026" usemap="#image-maps" alt="" data-reveal-id="firstModal" data-reveal />
<map name="image-maps" id="IMGMAPS">
<area shape="rect" coords="800,1024,802,1026" alt="Image Map" style="outline:none;" title="Image Map" href="selfie.jpg" />
<!--<div id="firstModal" class="reveal-modal" data-reveal> -->
<area alt="" title="" href="Shortlisted_selfie\VenkateshSittula.jpg" shape="poly" coords="248,177,365,177,364,257,248,256" style="outline:none;" target="_self" id="firstModal" class="reveal-modal" data-reveal />
<a class="close-reveal-modal">×</a>
<!-- </div> -->
This didn't made any difference to my results.
Edit 3: I am still struggling to get a working solution to this. Just to clarify again what I am looking for:
Base Image is a single image having areas 1, 2, 3, 4, 5.
Each area (1, 2, 3, 4, 5) has a corresponding image.
I want a functionality where if I click on area 1, it's corresponding image opens in a modal dialog, if I click on area 2, it's corresponding image opens in a modal dialog... so forth and so on for all the areas (only on click).
Is there a workaround for this?
Edit 4: As per Edrees's solution, I was able to implement the functionality what I looking for. Further, I need to fine-tune this solution by including a close button or link at top-right of the reveal-modal. I saw some foundation documents and found out that there is a class called **close-reveal-modal** used for this purpose, but I don't know how to implement this in my solution. Also I have images of sizes ranging from 612*640 to 900*1600 to 1280*960 to 1920*1080... how do I ensure that the image opened inside the modal resize proportionally (i.e. image maintains the ratio) as per the window size ?
Improve the solution using the following codepen link
Edit 5: The solution by #Edrees worked perfectly as long as I was viewing this page separately. However, when I embedded this page in MOJO Portal, Foundation CSS and JS completely screwed up the default behavior of MOJO Portal. It seems that default CSS was overridden by Foundation. Does anyone has a workaround for it? A plain jQuery to solve this without using Framework/plugin?
Edit 6: After facing issues with foundation framework, I realised that Rodrigo Leite has an answer to solve this issue. Although, I don't find any modal dialog being opened, it does give a feel of dialog box to the user and suffice for my requirements.
What changes I need:
I want the "div" to cover the entire window
Image should be displayed at the center (vertically and horizontally) of the window/screen
A close button at the top-right of the window/screen when the mapped image is displayed
A user should be able to click only the close button when image is opened. All other part of the window/screen should disable the click functionality / no action on clicking on any part of the screen except close button
NOTE: The close button can be displayed in any form i.e. image, button, etc.
You can create your own modal div and put it invisible, then, when the user click on area you can use javascript to show this modal and put your content inside it. Take a look:
css
#modal-background{
width: 100%;
height: 100%;
background-color: #000000;
position: fixed;
top: 0; left: 0;
display: none;
z-index: 99;
}
#modal-content{
background-color: #FFFFFF;
width: 500px;
height: 500px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -250px;
margin-top: -250px;
z-index: 100;
}
html
<div id='modal-background'>
<div id='modal-content'>
</div>
</div>
<img id="IMGMAPS" src="http://i.stack.imgur.com/zir2T.png" border="0" width="802" height="1026" orgWidth="802" orgHeight="1026" usemap="#image-maps" alt="" />
<map name="image-maps" id="IMGMAPS">
<area shape="rect" coords="800,1024,802,1026" alt="Image Map" style="outline:none;" title="Image Map" href="base.jpg" />
<area alt="" title="" data-imageurl="http://s.hswstatic.com/gif/smart-car-1.jpg" shape="poly" coords="248,177,365,177,364,257,248,256" style="outline:none;" target="_self" />
<area alt="" title="" data-imageurl="http://s.hswstatic.com/gif/smart-car-1.jpg" shape="poly" coords="386,193,501,180,510,258,394,271" style="outline:none;" target="_self" />
<area alt="" title="" data-imageurl="http://s.hswstatic.com/gif/smart-car-1.jpg" shape="poly" coords="539,221,650,250,631,327,518,299" style="outline:none;" target="_self" />
<area alt="" title="" data-imageurl="http://s.hswstatic.com/gif/smart-car-1.jpg" shape="poly" coords="128,277,222,271,228,369,135,375" style="outline:none;" target="_self" />
<area alt="" title="" data-imageurl="http://s.hswstatic.com/gif/smart-car-1.jpg" shape="poly" coords="238,281,352,265,360,325,359,342,250,359" style="outline:none;" target="_self" />
</map>
javascript (jquery):
$(document).ready(function(){
$('area').click(function(){
$('#modal-content').html('<img src=' + $(this).data('imageurl') +'>');
$('#modal-background').fadeIn();
});
$('#modal-background').click(function(){
closeModal();
});
});
function closeModal(){
$('#modal-background').fadeOut();
}
Hope it helps.
HTML code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/foundation/5.5.0/css/foundation.css">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.foundation5.zurb.com/foundation.js"></script>
</head>
<body>
<p>Click on the sun or on one of the planets to watch it closer:</p>
<img src="http://www.w3schools.com/tags/planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="" data-reveal-id="one">
<area shape="circle" coords="90,58,3" alt="Mercury" href="" data-reveal-id="two">
<area shape="circle" coords="124,58,8" alt="Venus" href="" data-reveal-id="three">
</map>
<img src="https://www.nasa.gov/sites/default/files/706436main_20121114-304-193blend_m6-orig_full.jpg" width="145" height="126" alt="Planets" id="one" data-reveal class="reveal-modal">
<img src="http://news.bbcimg.co.uk/media/images/65904000/jpg/_65904720_mdis_global_enhancedcolor_caloris_orth_hd.jpg" width="145" height="126" alt="Planets" id="two" data-reveal class="reveal-modal">
<img src="https://upload.wikimedia.org/wikipedia/commons/1/10/Kepler10b_artist.jpg" width="145" height="126" alt="Planets" id="three" data-reveal class="reveal-modal">
<script type="text/javascript">
$(document).foundation();
</script>
</body>
</html>
Javascript:
Files needed: JQuery + foundation.js
JS code:
$(document).foundation();
For a complete working code visit this link
I have set up a single page web app using AngularJS and in one of my partials I have an imagemap and would like to highlight the areas on mouseover. Ive tried searching around trying to figure out how to do this and I am not sure what is going wrong. Here is the code.
I tried using https://github.com/cowglow/AngularJS-maphilights as a resource
<section class="artistinfo">
<div class="artist cf">
<h1>Select a room for more details</h1>
<div class="info">
<img ng-src="images/housediagram.jpg" alt="Photo of thing" class="map" usemap="#houseMap">
<map name="houseMap" id="Map" class="maphilight">
<area name="kitchen" shape="poly" coords="197,193,348,194,349,301,197,302" href="#/kitchen"/>
<area name="livingroom" shape="poly" coords="349,194,349,300,562,301,561,192" href="#/livingroom"/>
<area name="laundry" shape="poly" coords="389,309,390,399,562,399,563,308" href="#/laundry"/>
<area name="basement" shape="poly" coords="387,309,388,399,197,399,197,306" href="#/basement"/>
<area name="office" shape="poly" coords="198,108,196,190,301,191,301,83,256,80" href="#/office"/>
<area name="bathroom" shape="poly" coords="301,83,302,190,418,191,417,83" href="#/bathroom"/>
<area name="bedroom" shape="poly" coords="419,83,417,192,560,191,560,109,494,80" href="#/bedroom"/>
</map>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
<script type="text/javascript" src="angular-maphilights.js"></script>
<script type="text/javascript" charset="utf-8">
angular.module('map', ['maphilights']);
</script>
</div>
You'll have to edit his code since he doesn't actually invoke the jQuery function that does the highlighting. You can replace the link function with the following
link: function (scope, element, attr) {
$(element).load(function () {
$(element).maphilight();
}).trigger('load');
}
Also, be sure to apply your directive on the <img> tag, not the <map> tag.
I am currently working on 2 functions; I created an image map for an image and want if someone hovers over this part of the image that on the right the price appears and a tooltip under the mouse that says "Discover" or similar.
Right now I have the following
<!DOCTYPE html>
<html>
<script>
function writeText(txt) {
document.getElementById("test").innerHTML = txt;
}
</script>
</head>
<body>
<img src ="test.png" alt="Jacket" usemap="#jacket" />
<p id="test"></p>
<map name="jacket">
<area shape="poly" coords="174,361,149,350,180,203,217,213"href="test"; title="Discover" alt="Shop Now" onmouseover="writeText('$60')" />
<map name="Map" id="Map">
<area href="test"; title="Shop Now" alt="Discover" shape="poly" coords="221,215,183,218,190,164" onmouseover="writeText('$60')" />
</map>
</map>
</body>
</html>
However there are a few problems:
The price does not disappear if the customer does not hover over the area
I am unable to show a tooltip.
Does anyone have an idea how to fix these problems?
I appreciate your help
You can add the following attribute to remove the price:
onmouseout="writeText('')"
And, you have extra semi-colons that may be the problem with your title not appearing. Try this instead:
<map name="jacket">
<area shape="poly" coords="174,361,149,350,180,203,217,213" href="test" title="Discover" alt="Shop Now" onmouseover="writeText('$60')" onmouseout="writeText('')" />
<map name="Map" id="Map">
<area href="https://jerry123.myshopify.com/products/product1" title="Shop Now" alt="Discover" shape="poly" coords="221,215,183,218,190,164" onmouseover="writeText('$60')" onmouseout="writeText('')" />
I have a smaller image which is of a control with 8 buttons, I have set up 8 area shapes so when what looks like a button is clicked the larger main image is updated.
When an area shape is clicked the relevant image loads, but I want the image to fade in and the old image to fade out.
Is this possible? Happy to explore Javascript and Jquery solutions. Thanks.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
<script type="text/javascript">
function showImage(image){
var mainImage = document.getElementById('mainImage');
mainImage.src = image;
}
</script>
</head>
<body>
<div><img src="button.jpg" width="260" height="193" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="61,21,120,55" href="#" onclick="showImage('A.jpg')" />
<area shape="rect" coords="147,21,205,54" href="#" onclick="showImage('B.jpg')" />
<area shape="rect" coords="60,58,121,90" href="#" onclick="showImage('C.jpg')" />
<area shape="rect" coords="147,59,205,92" href="#" onclick="showImage('D.jpg')" />
<area shape="rect" coords="61,92,121,125" href="#" onclick="showImage('E.jpg')" />
<area shape="rect" coords="146,96,205,128" href="#" onclick="showImage('F.jpg')" />
<area shape="rect" coords="60,128,122,163" href="#" onclick="showImage('G.jpg')" />
<area shape="rect" coords="146,131,204,164" href="#" onclick="showImage('I.jpg')" />
</map>
</div>
<div>
<img id="mainImage" src="A.jpg" />
</div>
</body>
</html>
I'd suggest having all the images on the page, positioned on top of each other. The below will add all the images linked to by the area to a container then crossfade when you click...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
$('#Map area').each(function(){
var area = $(this);
var img = $('<img>').attr('src', area.attr('href'));
$('#imgcontainer').append(img);
area.click(function(){
$('#imgcontainer img').stop().fadeOut();
img.stop().fadeIn();
return false;
})
});
$('#imgcontainer img:first-child').show();
});
</script>
<style>
#imgcontainer{width:260px;height:193px;}
#imgcontainer img{display:none;position:absolute;}
</style>
<img src="button.jpg" width="260" height="193" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="61,21,120,55" href="A.img" />
<area shape="rect" coords="147,21,205,54" href="B.img" />
<area shape="rect" coords="60,58,121,90" href="C.img" />
<area shape="rect" coords="147,59,205,92" href="D.img" />
<area shape="rect" coords="61,92,121,125" href="E.img" />
<area shape="rect" coords="146,96,205,128" href="F.img" />
<area shape="rect" coords="60,128,122,163" href="G.img" />
<area shape="rect" coords="146,131,204,164" href="I.img" />
</map>
<div id="imgcontainer"></div>
To do this you will need to create a new image and fade the old one out and the new one in.
This should work:
function showImage(image){
var mainImage = document.getElementById('mainImage');
$('#mainImage').before('<img src="' + image + '" id="newImage" />');
$('#mainImage').fadeOut().remove();
$('#newImage').attr('id','mainImage');
}
You should make sure with CSS that the new image is positioned behind the main one.
Source(s)
jQuery API - .append()
jQuery API - fading