gpt4 book ai didi

javascript - 如何添加/更改属性的值

转载 作者:行者123 更新时间:2023-12-02 13:45:07 25 4
gpt4 key购买 nike

我有一张图片,与 html 中的区域 map 一起使用

我在页面中添加了一些 Bootstrap ,但长话短说。

我想根据加载后图片的位置动态改变我的区域的坐标。
我得到图片的位置是这样的

var addLEFT = $("#body_hand_foot_image").position().left;
var addTOP = $("#body_hand_foot_image").position().top;

所以从这里我想将两个变量的值添加到区域的坐标中。以下是其中一个区域的示例。它们都是准确的,图片位于 x=0 - y=0 处。

<area class="joint" alt="Front Right Neck" href="#" joint="R_Neck_front" full="Right Neck" shape="circle" coords="126,92,8" />    

有什么想法吗?

经过一些帮助后的最终解决方案

function reconfCoords() {
var items = $('#jointMap').find('area');
items.each(function () {
var c = $(this).attr('coords');
var coords = c.split(',');

coords[0] = (Number(coords[0]) + Number($("#body_hand_foot_image").position().left)).toString();
coords[1] = (Number(coords[1]) + Number($("#body_hand_foot_image").position().top)).toString();
$(this).attr('coords',coords.join());

var a = $(this).attr('coords');
});
return true;
}

最佳答案

尝试做这样的事情:

var coords = $('area').attr('coords').split(',');

coords[0] = $("#body_hand_foot_image").position().left;
coords[1] = $("#body_hand_foot_image").position().top;

$('area').attr('coords',coords.join());

关于javascript - 如何添加/更改属性的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41464952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com