forked from stowball/jQuery-rwdImageMaps
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.rwdImageMaps.min.js
More file actions
11 lines (11 loc) · 1.12 KB
/
jquery.rwdImageMaps.min.js
File metadata and controls
11 lines (11 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
/*
* rwdImageMaps jQuery plugin v1.6
*
* 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) 2016 Matt Stow
* https://github.com/stowball/jQuery-rwdImageMaps
* http://mattstow.com
* Licensed under the MIT license
*/
;!function(t){t.fn.rwdImageMaps=function(){var a=this;return t(window).resize(function(){a.each(function(){if(void 0!==t(this).attr("usemap")){var a=t(this);t("<img />").on("load",function(){var r,i;if(a.data("w")&&a.data("h"))r=a.data("w"),i=a.data("h");else{if(r=a.attr("width"),i=a.attr("height"),!r||!i){var e=new Image;e.src=a.attr("src"),r||(r=e.width),i||(i=e.height)}a.data("w",r),a.data("h",i)}var n=a.width()/100,h=a.height()/100,s=a.attr("usemap").replace("#",""),d="coords";t('map[name="'+s+'"]').find("area").each(function(){var a=t(this);a.data(d)||a.data(d,a.attr(d));for(var e=a.data(d).split(","),s=new Array(e.length),c=0;c<s.length;++c)s[c]=c%2==0?parseInt(e[c]/r*100*n):parseInt(e[c]/i*100*h);a.attr(d,s.toString())})}).attr("src",a.attr("src"))}})}).trigger("resize"),this}}(jQuery);