I am looking at HTML hot spots and have a question with regards to an example I have found on a previous Stack Overflow Q&A.
Previous Stack OverFlow Area Example
In the first answer from 'Gibberish' he has provided a worked example on JSFiddle. JSFiddle Example from Gibberish
function hovIn() {
var areaID = $(this).attr('id');
//alert('['+areaID+']');
if (areaID == 'CUST_1') {
$('#myDiv').show();
}
}
function hovOut() {
$('#myDiv').hide();
}
$('map area').hover(hovIn, hovOut);
#num_cust1 {
padding: 10px;
background-color: yellow;
position: absolute;
top: 60px;
left: 180px;
}
#num_cust2 {
padding: 10px;
background-color: yellow;
position: absolute;
top: 60px;
left: 40px;
}
#num_cust3 {
padding: 10px;
background-color: yellow;
position: absolute;
top: 160px;
left: 180px;
}
#myDiv {
display: none;
width: 50%;
height: 50px;
padding: 10px;
background-color: skyblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Instructions: Mouse over computer's monitor to see hidden DIV
<!--<img src="http://www.proprofs.com/quiz-school/upload/yuiupload/2014513384.jpg" width="400" height="400" />-->
<div id="imagemap">
<img src="http://img716.imageshack.us/img716/8287/3ylp.jpg" width="275" height="207" usemap="#Map" border="0" />
<map name="Map">
<area shape="poly" coords="105,26,107,126,257,140,256,27" href="#" id="CUST_1" name="CUST:1" />
<area shape="poly" coords="10,21,14,178,71,184,69,19" href="#" id="CUST_2" name="CUST:2" />
<area shape="poly" coords="113,145,94,172,241,192,251,164,250,164" href="#" id="CUST_3" name="CUST:3" />
</map>
<p>
<div id="myDiv">This DIV hidden unless hover over the computer's monitor</div>
</p>
</div>
<!-- Yellow DIV ID numbers overlaid on top of computer components -->
<div id="num_cust1">1</div>
<div id="num_cust2">2</div>
<div id="num_cust3">3</div>
I understand how most of the answer works apart from, if I click on any of the three defined Polygon areas they become highlighted by a blue outline - but I can't see the code that makes this happen (e.g. a click event). Can anyone explain how/why they show up blue without any code (that I can see)??
Screen grab of Fiddle output with blue clicked area shown:
The map tag is used to define a client-side image-map. An image-map is an image with clickable areas.
The required name attribute of the map element is associated with the img's usemap attribute and creates a relationship between the image and the map.
The map element contains a number of area elements, that defines the clickable areas in the image map.
To hide the outline you can do
map area {
outline: none;
}
<map name="primary">
<area shape="circle" coords="75,75,75" href="#">
<area shape="circle" coords="275,75,75" href="#">
</map>
<img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">
Using the outine css property you can do a lot of stuff to the map area.For example you want to change the color from blue
to red
you can do
map area{
outline-color: red;
}
<map name="primary">
<area shape="circle" coords="75,75,75" href="#">
<area shape="circle" coords="275,75,75" href="#">
</map>
<img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">