I have a picture that I use with a Area Map in html
I have added some bootstrap to the page, but long story short.
I would like to dynamically alter the coordinates of my areas based on the position of the picture after loading.
I get the position of the picture like this
var addLEFT = $("#body_hand_foot_image").position().left;
var addTOP = $("#body_hand_foot_image").position().top;
So from here I want to add the values of the two variables to the coordinates of the areas. Below is an example of one of those areas. They are all accurate of the picture is located at x=0 - y=0.
<area class="joint" alt="Front Right Neck" href="#" joint="R_Neck_front" full="Right Neck" shape="circle" coords="126,92,8" />
Any Ideas?
Final Solution after some help
function reconfCoords() {
var items = $('#jointMap').find('area');
items.each(function () {
var c = $(this).attr('coords');
var coords = c.split(',');
coords[0] = (Number(coords[0]) + Number($("#body_hand_foot_image").position().left)).toString();
coords[1] = (Number(coords[1]) + Number($("#body_hand_foot_image").position().top)).toString();
$(this).attr('coords',coords.join());
var a = $(this).attr('coords');
});
return true;
}
coordsattr ofareatag ?coordsattribute, parse the results as integers, add some value to them and serialize them back into the attribute? What are your problems with achieving this?addLEFTwill be added to thexcoords andaddTOPto theycoords. The third coord (radius) can be left alone. Then join the values back as strings, which is not difficult either. If you get into trouble, search for information about the specific sub-problem you're solving.var co = $('area').attr('coords').split(','); co[0]+addLeft; co[1]+addRight; $('area').attr('coords', co.join(','))