Skip to content

Instantly share code, notes, and snippets.

@mrdoob
Last active February 14, 2024 05:02
Show Gist options
  • Save mrdoob/e69fd7009736f2ba99a8968c682a8653 to your computer and use it in GitHub Desktop.
Save mrdoob/e69fd7009736f2ba99a8968c682a8653 to your computer and use it in GitHub Desktop.
Responsive image map coords
// @mrdoob: Can't believe image maps aren't responsive
window.onload = function () {
var image = document.getElementById( 'image' );
var delta = image.clientWidth / 1024;
var map = document.getElementById( 'map' );
var areas = map.getElementsByTagName( 'area' );
for ( var i = 0; i < areas.length; i ++ ) {
var area = areas[ i ];
var coords = area.coords.split( ',' );
for ( var j = 0; j < coords.length; j ++ ) {
coords[ j ] *= delta;
}
area.coords = coords.join( ',' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment