I am creating an interactive map in jQuery, and am using a custom hand-drawn map. I have a series of “trigger points” placed throughout the map, absolutely positioned, relative to the size of the map. WHen a use hovers over these trigger points, a tooltip is displayed with information about the location.
HTML/CSS:
<div id="map" style="position:relative; background: url(images/map.jpg">
<div class="trigger" data-loc="locationA" style="position:absolute; left:10px; top:3px"><h1 class="tooltip">Location A Title</h1></div>
<div class="trigger" data-loc="locationB" style="position:absolute; left:0px; top:24px"><h1 class="tooltip">Location B Title</h1></div>
<div class="trigger" data-loc="locationC" style="position:absolute; left:140px; top:35px"><h1 class="tooltip">Location C Title</h1></div>
<div class="trigger" data-loc="locationD" style="position:absolute; left:70px; top:103px"><h1 class="tooltip">Location D Title</h1></div>
</div>
JQuery:
$(".trigger").hover(function(){
$(this).find(".tooltip").fadeIn();
}, function(){
$(this).find(".tooltip").fadeOut();
});
A few Questions:
1) Is this the best way to go about a basic interactive map with JQuery?
2) I want to have a list of locations off to the right. When a user clicks on the link it should ALSO trigger the tooltip for that pertaining link. As shown above, there is a data-loc attribute in each trigger-point. If I set the same data-points in the anchor links to the right, how would I use jQuery to link them up and trigger the fading in and out of the pertaining tooltip?
To my knowledge there isn’t a best way to do this. One slightly more descriptive way is to use the area tag instead of a div.
Then similarly:
Probably a little more work to write the custom functions for showing a tooltip. (note: I’ve never used Area myself. )
Update
There are a couple of ways to accomplish this.
A semi-hacky way, since you are already using absolutes is to put another div around the current div’s but have them absolutely positioned way to the right. Hacky but works.
I wouldn’t do that, cause this would be way better in my opinion:
Then with jQuery: