Clicking only non-transparent area of the image on html - javascript

I want my img be clickable for only its non-tansparent area because it blocks images that are behind.For example when I click north France it chooses Germany. How can this be possible?
I have something like this and all of the countries are an image on html page.
Here is the image of my website:

Your image is a JPEG. It has no transparent parts. However, the easiest way to assign different actions to different regions would be to use an image map. I used this online tool to create areas corresponding to France and Germany. You should be able to create areas for all the other countries in just a few minutes.
<map name="Map" id="Map">
<area alt="" title="" href="#" shape="poly" coords="248,165,275,136,
316,127,327,117,314,96,321,77,337,68,344,68,336,90,332,97,335,114,
352,120,373,111,387,125,394,163,361,175,367,193,378,198,368,205,369,
215,363,214,350,226,323,240,288,238,312,197,274,185"
onclick="alert('Germany'); return false" />
<area alt="" title="" href="#" shape="poly" coords="159,199,194,202,
196,186,202,184,218,192,235,179,236,169,249,167,277,186,314,197,289,
235,302,239,304,274,292,286,260,281,250,298,222,289,215,291,193,285,
202,256,196,232,175,216,159,213"
onclick="alert('France'); return false" />
<!-- et cetera -->
</map>
<img src="http://i.stack.imgur.com/pGuAF.jpg" alt="" usemap="#Map" />

Related

Can I create a semicircle shape in html image area map?

I need to make a semicircle shape on an image using the Html image map tag.
This is the code but it makes a circle.
<img src="floorplan1.png" usemap="#image-map">
<map name="image-map">
<area target="" alt="" title="" href="" coords="494,686,91" shape="circle">
</map>
Is it possible to do this?
If yes, then please tell the way to do it.
You can use shape=poly and define each coord. Look at the example below. You can also use https://www.image-map.net/ to generate it online on your image.
In below example try clicking on the plant.
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR4C5coWnjUpQ619SpeV_MwkBj57xOa-0Jd-mLAHP2R2Ic9OY_G" usemap="#image-map">
<map name="image-map">
<area target="" alt="" title="" href="" coords="181,257,245,246,292,201,307,135,269,76,226,53,183,55,185,151" shape="poly">
</map>

Place image icon on image map and make it clickable using javascript

I am relative new to JavaScript. We have floor plan image and we need to place a seat image on office floor plan and make it clickable.
We need to display certain information like seat no, vacant or occupied, Name of the person if it is occupied etc. on mouse over event or on clicking. I tried with image map functionality but unable to place icon on the image map.
Please help me on this issue.
<img id="feature" src="trignometry-page-001.jpg" border="0" width="1754" height="1240" orgWidth="1754" orgHeight="1240" usemap="#image-maps-2014-10-19-105116" alt="" />
<map name="feature">
<area alt="" title="" shape="rect" class="group" coords="228,560,250,585" target="_self" onClick="alert('hi')" data-maphilight="{"strokeColor":"0000ff","strokeWidth":5,"fillColor":"ff0000","fillOpacity":0.6}" />
<area shape="rect" coords="1752,1238,1754,1240" alt="Image Map" style="background-color: transparent;border: 1px solid yellow;" title="Image Map" />
</map>
Maybe some javascript events will help you to understand more how this works.
http://javascript.info/tutorial/mouse-events
And you can check this canvas sample for multiple areas, this is using Jquery.
https://github.com/neshte/jquery-canvas-area-draw
It would be better to have the code you are using for this.
Hope this helps.

change clickable coordinate image to css

Im trying to make the background image of my website clickable in certain coordinates. I dont have the ability of editing the main template as the script im using is prebuilt to add custom code into it (phpfox).
The problem i have is the code i am using is html and i need it to be css
<img url="../image/layout/bg.png" width="1920" height="1080" border="0" usemap="#Map" />
<map name="Map">
<!-- #$-:Image map file created by GIMP Image Map plug-in -->
<!-- #$-:GIMP Image Map plug-in by Maurits Rijk -->
<!-- #$-:Please do not edit lines starting with "#$" -->
<!-- #$VERSION:2.3 -->
<!-- #$AUTHOR:ImithRian -->
<area shape="rect" coords="43,36,174,803" href="http://www.battlefieldsquad.com/" />
<area shape="rect" coords="1469,99,1866,225" href="http://www.battlefieldsquad.com/index.php?do=/battlefield4/" />
<area shape="rect" coords="1564,457,1793,619" href="http://www.battlefieldsquad.com/index.php?do=/pages/3/" />
<area shape="rect" coords="1597,657,1773,878" href="http://www.esl.eu/eu/team/7931638/" />
</map>
Any suggestions ?
I can't think of a pure css-Solution. But if you want to put the image into a div as background,
you can get the position of a click relativ to your site via jQuery
HTML:
<div class="background">
Some content and a background image
</div>
Javascript:
$('.background').click(function(event){
console.log(event.pageX + " " + event.pageY);
//at some coordinate do something (e.g. go to another site)
});
As far as I know, the coordinates for an image map is just an html feature, not available as a style rule in css. What you can do if you want to change the values of the coordinates without having access to the html is reaching the element via javascript and performing the modifications then. I can provide you that code if you are interested in doing it that way.
This is the way you can tackle that with javascript (THE FIDDLE HERE)
Let's say you have a world map and you have defined a clickable link for the continents: North America, South America, Europe and Asia, Africa.
<img src="http://3.bp.blogspot.com/--Qn8gNCWlUc/UVhKBl5o5aI/AAAAAAAACYI/wMLgckCYQIs/s1600/Screen+Shot+2013-03-31+at+12.59.10+AM.png" border="0" usemap="#Map" />
<map name="Map">
<area shape="rect" title="north america" coords="43,36,174,803" href="http://www.battlefieldsquad.com/" border="2" />
<area shape="rect" title="south america" coords="1469,99,1866,225" href="http://www.battlefieldsquad.com/index.php?do=/battlefield4/" />
<area shape="rect" title="eurasia" coords="1564,457,1793,619" href="http://www.battlefieldsquad.com/index.php?do=/pages/3/" />
<area shape="rect" title="africa" coords="1597,657,1773,878" href="http://www.esl.eu/eu/team/7931638/" />
</map>
<br /><br />
<button type="button" id="fixer">Fix this mess!</button>
When you hover the mouse on the map you notice that just the shape for North America is there and in a wrong position (a tip shows up after a second).
Bellow the map you have a button to fix that. That button execute this code:
document.getElementById("fixer").onclick=function(){
var coords = ["70,100,400,320", "320,350,425,580", "510,100,1050,300", "480,300,680,500"];
var mapper = document.getElementsByTagName("area");
for(var i = 0, j = mapper.length;i < j;i++){
mapper[i].coords = coords[i];
}
}
And once you press the button you can hover the mouse then on the continents and check they are showing up now and in the right position, because the js code changes the coordinates of each shape:
var coords = ["70,100,400,320", "320,350,425,580", "510,100,1050,300", "480,300,680,500"];
That's an array with the right coordinates for each area shape from top to bottom.
The rest of the code is to set up the coordinates. You just have to edit the above line to meet your own coordinates.
I hope it helps. And by the way, if you are finally going to use this approach, you might want to add the tag javascript to your question. Regards.

Jump to a specific location on an image map

I have a big image with an HTML <map>, and I want to jump to a particular region on that image. I have used the <area /> tag for marking the locations
Take a look at the code :
<img src="demo_files/k3.png" id="target" alt="Map" usemap="#powerpuffgirls" />
<map name="powerpuffgirls">
<area shape="rect" coords="624,137,671,167" href="#" id="ppg" title="The Powerpuff Girls" alt="The Powerpuff Girls" />
<area shape="rect" coords="99,2685,161,2723" href="#" name="ppg1" title="The Powerpuff Gidrls" alt="The Powerpuff sGirls" />
</map>
however, I am unable to move to any region on the image.
Edit: Any other approach for moving to an image's particular region would be great !!
Try this link
$('a.links').click(function(e){
e.preventDefault();
var coor = $(this.hash).attr('coords').split(',');
$('html,body').scrollTo(coor[0], coor[1]);
});
i have used the plugin scrollTo
the script will prevent default function of a tag and will get the coordinates attribute from the area tag with the id from the href attribute and calculate the positions and scroll to that position
Check this demo i have created...
Try to navigate the areas by id...
<div>Go to one Go to two</div>
You have to play with the area coordinates in it...
http://jsfiddle.net/D9W6C/

Change background of mapped image hotspot on mouseover

I have an image map of 3 polygons. The actual image hotspots are complex shapes consisting of multiple curves and edges.
<img src="/images/map.gif" alt="HTML Map"
border="0" usemap="#map"/>
<map name="map">
<area shape="poly"
coords="74,0,113,29,98,72,52,72,38,27"
href="index.htm" alt="area1" />
<area shape="poly"
coords="22,83,126,125"
href="index.htm" alt="area2" />
<area shape="poly"
coords="73,168,32"
href="index.htm" alt="area3" />
</map>
I've created a duplicate of map.gif called map_over.gif rendered in a different color. What I'd like to do is change the area within the clickable hotsposts of map.gif to map_over.gif on mouse hover. Any suggestions as to how I could accomplish this with CSS or Javascript? Thanks in advance.
aThis is an easy one.
html:
<img src="/images/map.gif" alt="HTML Map" border="0" usemap="#map" id="mappedImage" />
css:
img#mappedImage:hover {
background: url("/images/map2.gif") no-repeat scroll 0 0 transparent;
}
Should do the trick. You could use the background-image: url("/images/map2.gif") as well - background provides more options at once like background-repeat, background-position etc.
As for any questions about css I can recommend http://www.css4you.de/borderproperty.html as a good reference site with good examples.

Categories