Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image map/ area coordinate update on resize

Tags:

html

jquery

I'm making a main control page with different links on a image now the only problem is I want the image to fit the whole page and re-size (the window) if they shrink it (to a certain degree) and enlarge it.

<img src ="image/main.jpg" style="width:100%;height:100%; min-width:600px; min-height:400px;" alt="Main" usemap="#MainMap">

<map name="MainMap">
<area id="login" class="login" shape="circle" coords="91,677,92">
<area id="money_management" class="money" shape="circle" coords="598,680,92">
<area id="withdraw_history" shape="circle" coords="596,304,67">
<area id="transaction_history" shape="circle" coords="784,624,67" href="History.html">
<area id="cart" shape="circle" coords="396,698,67,92">
<area id="buy" shape="circle" coords="898,352,92">
<area id="sell" shape="circle" coords="718,438,92">
<area id="new" shape="circle" coords="570,132,92" href="New.html">
</map> 

I had this before when i made the image static and left it to work on something else, I wanted the coordinates to be updated after they re-size the window I know how to detect re-size in jquery I can't find any syntax example on updating coordinates.

like image 897
Thao Nguyen Avatar asked Jan 16 '23 04:01

Thao Nguyen


2 Answers

Here is a great jQuery PlugIn that does exactly what you wanted:

Responsive Image Maps jQuery Plugin

/*    
* rwdImageMaps jQuery plugin v1.4    
*    
* Allows image maps to be used in a responsive design by recalculating 
* the area coordinates to match the actual image size on load and 
* window.resize     
*    
* Copyright (c) 2012 Matt Stow    
* https://github.com/stowball/jQuery-rwdImageMaps    
* http://mattstow.com    
* Licensed  under the MIT license
*/

Hope that helps

like image 163
danie7L T Avatar answered Jan 28 '23 10:01

danie7L T


David Bradshaw wrote a nice little library that solves this problem. It can be used with or without jQuery.

Available here: https://github.com/davidjbradshaw/imagemap-resizer

like image 32
Grodriguez Avatar answered Jan 28 '23 10:01

Grodriguez