first check out the image for a better understanding of what I want to do. The red points on the picture will be clickable. When you click on them a description will pop up.
I saw the use of HTML <area> tag and a JS function with image coordinates.
Is there any ready made library available for this ?
You're best off making use of an <img> and the <map> element. From here you can set <area> children with a circular shape, and specify the the co-ordinates. These are in the format x,y from the top-left pixel. With a circle, the third value is the diameter. You can link these off, or attach an event handler to display a popup:
img {
height: 100%;
}
area {
fill: blue;
}
<img src="https://i.stack.imgur.com/q9ZX6.png" usemap="#housemap">
<map name="housemap">
<area shape="circle" coords="0,0,82,126" href="1.htm" alt="1">
<area shape="circle" coords="190,58,30" href="2.htm" alt="2">
<area shape="circle" coords="90,58,30" href="3.htm" alt="3">
<area shape="circle" coords="90,58,30" href="4.htm" alt="4">
</map>
Related
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>
Is it possible, using either HTML canvas or Javascript, to click on part of an image and, depending on which part you clicked, it trigger a Javascript event?
So, for example;
If I have an image of a watch and the user clicks on the strap, this triggers a modal with content relating to the strap. Similarly, if they click on one of the watch hands, this triggers a different modal.
You can use the HTML tag to do so, Please check the <area> tag in html it might serve your purpose.
Check the below code may help you:
W3 Schools - Areamap
And you can also use <canvas> or <svg> with the help of Fabric.js you can get the thing done in much more advance way.
Check this link you will get really cool stuff to do with image or canvas and svg:
MDN - Canvas API Tutorial
Thanks
function runfunc(planetId) {
console.log('You selected:', planetId);
}
.as-console-wrapper { max-height: 2.8em !important; }
<p>Click on the Sun or on one of the planets to see which one was selected.</p>
<img src="https://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" id="Sun" onclick="runfunc(this.id)">
<area shape="circle" coords="90,58,3" alt="Mercury" id="Mercury" onclick="runfunc(this.id)">
<area shape="circle" coords="124,58,8" alt="Venus" id="Venus" onclick="runfunc(this.id)">
</map>
what I am trying to do is to create menu, instead of links, a clickable image. However, these images are parallax layers. How should I approach this ? Should the clickable images be on separate layers ?
This is the image I am going to use. I would like that tower in background to take you to gallery, but at the same time, that layer, as mentioned will be parallax.
Any ideas ?
It's probably a good idea if you create a separate parallax layer that contain absolute positioned links as a form of navigation. If you strictly want to map certain areas on the image as links, you might want to use a tag as in this example taken from here:
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
The shape defines the type of area of each clickable area, the coords define the perimeter of said areas; the href attributes define where the page navigates if said area is clicked.
To achieve this with a non-basic shape, you can set the type to "poly" and then set the polygon's each anchor point's coordinates as such:
<area shape="poly" coords="450,25,435,60,400,75,435,90,450,125,465,90,500,75,465,60" href="yellow.html" alt="Yellow star.">
The below code works perfectly to reveal an image when a user mouses over an hotspot of an image map. The only problem? When clicked 'this.href' of course takes the user to the hotspot image itself. I'd like to reserve 'href' to send the users to the page of my choosing.
Is it possible to use "title" rather than 'href' to define the hotspot image? If so, please show details, I'm very new to javascript, thank you!
<script type="text/javascript">
function ShowPicC(sImage){document.housec.src = sImage}
</script>
<img border="0" src="main-image.png" width="640" height='640' usemap="#FPMap0">
<map name="FPMap0">
<area onmouseover='ShowPicC(this.href)' href='hotspot1.png' alt="thisalt" title="can-png-go-here.png" shape="circle" coords="400,400,20">
<area onmouseover="ShowPicC(this.href)" href="hotspot2.jpg" alt="youralt" title="can-png-go-here2.png" shape="circle" coords="420,420,20">
<area onmouseover="ShowPicC(this.href)" href="hotspot3.jpg" alt="differentalt" title="can-png-go-here3.png" shape="circle" coords="440,440,20">
<area onmouseover="ShowPicC(this.href)" href="hotspot4.jpg" alt="whateveralt" title="can-png-go-here4.png" shape="circle" coords="460,460,20">
</map>
<img name="housec" src="starter-hotspot-image.png" width="192" height="170">
Sure, although title isn't a valid property of area. Did you try it?
<area onmouseover="ShowPicC(this.title)" title="someotherimage.jpg" ...
You may be better off using a data attribute:
<area data-image="someotherimage.jpg" ...
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes
I've got an image map with 20 area elements, only four shown below. I want to style each area so that a blue border appears whenever a user hovers over it - all the area shapes are rectangles.
<map id="mymap" name="mymap">
<area shape="rect" coords="0,0,223,221" href="http://..." />
<area shape="rect" coords="226,0,448,221" href="http://..." />
<area shape="rect" coords="451,0,673,223" href="http://..." />
<area shape="rect" coords="677,0,1122,223" href="http://..." />
...
</map>
I've tried using CSS to style each area, but it's not working. And I've tried to put an onmouseover=color() on the map element and call the following function, but that doesn't seem to be working either:
function color() {
var blueboxes = document.getElementsByTagName('area');
for(var i=0; i<blueboxes.length; i++) {
blueboxes[i].style.border = 'solid blue 5px';
}
}
mapper.js can be used for this.
Mapper.js 2.4 allows you to add automatic area highlighting to image maps on your webpages (inc. export to SVG).
It works in all the major browsers - Mozilla Firefox 1.5+, Opera 9+, Safari and IE6+. On older browsers, it can use "jsgraphics" from Walter Zorn (if installed), else it'll degrade and your visitors won't notice a thing.
Sample code from that website:
Please note that everything below this line is his code and wording, not mine. Full attribution belongs to the link above.
Setting Up
Download mapper.js and include it into your webpage.
<script type="text/javascript" src="wz_jsgraphics.js"></script>
<script type="text/javascript" src="mapper.js"></script>
"wz_jsgraphics.js" is copyright by Walter Zorn and not part of the distribution!
Using It
To get the highlighting just add a class="mapper" to an div surrounded image.
<div>
<img src="..." class="mapper" usemap="..." alt="...">
</div>
To get individual area highlightings add one or more classes to the area.
<map>
...
<area shape="poly" class="noborder icolor00ff00" href="#" coords="...">
...
</map>
To get multiple area selections add one or more id's to the areas rel attribute.
<map>
...
<area shape="poly" id="blue" rel="green,red" href="#" coords="...">
<area shape="poly" id="green" rel="red,blue" href="#" coords="...">
<area shape="poly" id="red" rel="green,blue" href="#" coords="...">
...
</map>
To force a group of areas using the attributes of the initial area.
<map>
...
<area shape="rect" id="black" class="icolor000000 forcegroup" rel="green,red,blue" href="#" coords="...">
...
</map>
The area tag can't be styled like a normal anchor. I would use a different approach. You could apply your image to a div as the background-image and then position clickable elements over the div by using position: absolute.
Take a look at this technique: http://www.alistapart.com/articles/cssmaps/
Can Raphaeljs helps?
Have a look at this sample :)
Usually the approach I see is to build the imagemap itself out of different images in CSS. Here's a good example of this:
http://ago.tanfa.co.uk/css/examples/europe-map.html