Skip to content

Commit 720ac6d

Browse files
committed
Initial commit
0 parents  commit 720ac6d

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
jQuery RWD Image Maps
2+
==============================
3+
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
5+
6+
* * *
7+
8+
Usage:
9+
10+
$('img[usemap]').rwdImageMaps();

jquery.rwdImageMaps.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* rwdImageMaps jQuery plugin v1.0
3+
*
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
5+
*
6+
* Copyright (c) 2012 Matt Stow
7+
* http://mattstow.com
8+
* Licensed under the MIT license
9+
*/
10+
(function($) {
11+
$.fn.rwdImageMaps = function() {
12+
var $img = this;
13+
var rwdImageMap = function() {
14+
$img.each(function() {
15+
if (typeof($(this).attr('usemap')) == 'undefined')
16+
return;
17+
var w = $(this).attr('width'), h = $(this).attr('height'), wPercent = $(this).width()/100, hPercent = $(this).height()/100, map = $(this).attr('usemap').replace('#', ''), c = 'coords';
18+
$('map[name="' + map + '"]').find('area').each(function() {
19+
if (!$(this).data(c))
20+
$(this).data(c, $(this).attr(c));
21+
var coords = $(this).data(c).split(','), coordsPercent = new Array(coords.length);
22+
23+
for (var i = 0; i < coordsPercent.length; ++i) {
24+
if (i % 2 === 0)
25+
coordsPercent[i] = parseInt(((coords[i]/w)*100)*wPercent);
26+
else
27+
coordsPercent[i] = parseInt(((coords[i]/h)*100)*hPercent);
28+
}
29+
$(this).attr(c, coordsPercent.toString());
30+
});
31+
});
32+
};
33+
rwdImageMap();
34+
$(window).resize(function() {
35+
rwdImageMap();
36+
});
37+
};
38+
})(jQuery);

jquery.rwdImageMaps.min.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* rwdImageMaps jQuery plugin v1.0
3+
*
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
5+
*
6+
* Copyright (c) 2012 Matt Stow
7+
* http://mattstow.com
8+
* Licensed under the MIT license
9+
*/
10+
(function(a){a.fn.rwdImageMaps=function(){var c=this;var b=function(){c.each(function(){if(typeof(a(this).attr("usemap"))=="undefined"){return}var d=a(this).attr("width"),f=a(this).attr("height"),e=a(this).width()/100,i=a(this).height()/100,g=a(this).attr("usemap").replace("#",""),j="coords";a('map[name="'+g+'"]').find("area").each(function(){if(!a(this).data(j)){a(this).data(j,a(this).attr(j))}var l=a(this).data(j).split(","),k=new Array(l.length);for(var h=0;h<k.length;++h){if(h%2===0){k[h]=parseInt(((l[h]/d)*100)*e)}else{k[h]=parseInt(((l[h]/f)*100)*i)}}a(this).attr(j,k.toString())})})};b();a(window).resize(function(){b()})}})(jQuery);

0 commit comments

Comments
 (0)