Last active
February 14, 2024 05:02
-
-
Save mrdoob/e69fd7009736f2ba99a8968c682a8653 to your computer and use it in GitHub Desktop.
Responsive image map coords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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