解析图像地图上的坐标

发布于 2024-09-12 09:19:06 字数 1146 浏览 5 评论 0原文

我有一个可点击的美国 html 图像地图,但我想将其大小调整为当前大小的一半。这意味着我还需要将所有坐标值分成两半,以便单击区域仍然准确。除了手动执行此操作之外,是否有一种简单的方法可以遍历 DOM 并自动将所有坐标除以 2?这是 HTML:

    <div id="map">
    <img class="map" src="images/us_map.jpg" width="960" height="593" usemap="#usa">
    <map name="usa">
    <area href="#" title="SC" shape="poly" coords="735,418, 734,419, 731,418, 731,416, 729,413, 727,411, 725,410, 723,405, 720,399, 716,398, 714,396, 713,393, 711,391, 709,390, 707,387, 704,385, 699,383, 699,382, 697,379, 696,378, 693,373, 690,373, 686,371, 684,369, 684,368, 685,366, 687,365, 687,363, 693,360, 701,356, 708,355, 724,355, 727,356, 728,360, 732,359, 745,358, 747,358, 760,366, 769,374, 764,379, 762,385, 761,391, 759,392, 758,394, 756,395, 754,398, 751,401, 749,404, 748,405, 744,408, 741,409, 742,412, 737,417, 735,418"></area>
    <area href="#" title="HI" shape="poly" coords="225,521, 227,518, 229,517, 229,518, 227,521, 225,521"></area>
    <area href="#" title="HI" shape="poly" coords="235,518, 241,520, 243,520, 244,516, 244,513, 240,512, 236,514, 235,518"></area>

'

I have a clickable html image map of the US, but I would like to resize it to half its current size. This means I'm also going to need to divide all the coord values in half so that the click areas are still accurate. Instead of doing this manually, is there an easy way to traverse the DOM and automatically divide all the coordinates by 2? Here's the html:

    <div id="map">
    <img class="map" src="images/us_map.jpg" width="960" height="593" usemap="#usa">
    <map name="usa">
    <area href="#" title="SC" shape="poly" coords="735,418, 734,419, 731,418, 731,416, 729,413, 727,411, 725,410, 723,405, 720,399, 716,398, 714,396, 713,393, 711,391, 709,390, 707,387, 704,385, 699,383, 699,382, 697,379, 696,378, 693,373, 690,373, 686,371, 684,369, 684,368, 685,366, 687,365, 687,363, 693,360, 701,356, 708,355, 724,355, 727,356, 728,360, 732,359, 745,358, 747,358, 760,366, 769,374, 764,379, 762,385, 761,391, 759,392, 758,394, 756,395, 754,398, 751,401, 749,404, 748,405, 744,408, 741,409, 742,412, 737,417, 735,418"></area>
    <area href="#" title="HI" shape="poly" coords="225,521, 227,518, 229,517, 229,518, 227,521, 225,521"></area>
    <area href="#" title="HI" shape="poly" coords="235,518, 241,520, 243,520, 244,516, 244,513, 240,512, 236,514, 235,518"></area>

'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无风消散 2024-09-19 09:19:06

我有类似的东西:

var rects = document.getElementsByTagName('area');
var ratio = 1/2;

for (i = 0; i < rects.length; i++) {
    coords = rects[i].coords.split(",");
    coord = '';
    for (j = 0; j < coords.length; j++) { 
        newCoord = coords[j].trim() * ratio;
        coord += newCoord;
        if (j + 1 < coords.length) {
            coord +=', ';
        }
    }       
    rects[i].coords = coord;
}

I have something like:

var rects = document.getElementsByTagName('area');
var ratio = 1/2;

for (i = 0; i < rects.length; i++) {
    coords = rects[i].coords.split(",");
    coord = '';
    for (j = 0; j < coords.length; j++) { 
        newCoord = coords[j].trim() * ratio;
        coord += newCoord;
        if (j + 1 < coords.length) {
            coord +=', ';
        }
    }       
    rects[i].coords = coord;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文