Reputation: 188
I'm using an Area Map over my image to allow users to select points which perform various JavaScript functions.
The coordinates of the shapes are hard coded into the html page as this allows my script to work on various pages. Unfortunately I now need to have the page work at various resolutions, which also requires that the picture scale as a percentage of the parent Div (no work around on this, customer requirement).
As area maps uses coordinates and percentages aren't yet supported I was wondering what the best approach to this should be?
The only options I can think of are:
Upvotes: 1
Views: 1660
Reputation: 1912
You could do some coordinate recalculations in javascript on page load and on window.resize. With jQuerys width()
and height()
functions you can get the current image size, divide it by the width and height of the parent div
and apply these factors to your image map coordinates.
I think that's basically what this jQuery plugin does (not tested!): http://mattstow.com/experiment/responsive-image-maps/rwd-image-maps.html
Another solution would be to use CSS transforms (if you don't care for legacy browser support ;-)). You could check for the current document.width() and document.height() values and then apply a scale value to the img
and the map
tag.
Upvotes: 2