1

I'm trying to place an image over another based on the coordinates.

My html is:

<button id="add">add image</button>
<div id="container">
    <img src="http://www.rangde.org/newsletter/nov11/images/real_tree.png" width="400" usemap="#treemap" />
</div>
<map name="treemap">
    <area shape="circle" coords="345,483,13" alt="Venus" href="#" />
    <area shape="circle" coords="333,361,13" alt="Venus" href="#" />
    <area shape="circle" coords="302,284,13" alt="Venus" href="#" />
    <area shape="circle" coords="79,350,13"  alt="Venus" href="#" />
    <area shape="circle" coords="55,489,13"  alt="Venus" href="#" />
</map>

My script is:

$('document').ready(function(){
    $('#add').click(function() {
        $('area[alt=Venus]').css('background','http://www.rangde.org/newsletter/nov11/images/green-ball.png');
    });
});

Here is my jsfiddle

Suresh Pattu
  • 6,083
  • 16
  • 59
  • 91

4 Answers4

1

I'm afraid, it is not possible to set background on <area> as it is not a graphical element. If it was possible some would use it earlier to create simple <canvas> :)

Here is a forum, where people speak about similar

Alexander Yezutov
  • 3,144
  • 2
  • 21
  • 23
1

This isn't an appropriate use of an image map, unfortunately, because they're not actually an element that can be styled.

However, if you switched this over to use some absolutely positioned divs in the same location as your mapped circles, combined with the CSS border-radius property, you can create the effect you're looking for: http://jsfiddle.net/N6Sbt/1/

That should be a pretty straightforward solution to your problem.

justisb
  • 7,081
  • 2
  • 26
  • 44
0

I'll use <a> instead of map, which should help you achieve the same thing. Just set them as 'position:absolute' with 'top' and 'left' having the value of coordinates, and 'width', 'height' with the value of size (as it's only 13 pixels, I don't thing rectangle and circle will be that different). Assign them with a class name so you can select them with jQuery. And don't forget to set the 'container' as 'position:relative'.

Xun Yang
  • 4,209
  • 8
  • 39
  • 68
0

Try out this plugin it might help.still in development but you can have a look at it. http://archive.plugins.jquery.com/project/maphilight Here is the demo link http://davidlynch.org/projects/maphilight/docs/demo_world.html

koneru
  • 76
  • 2