自适应图片热区坐标:

  html:

<div >
    <area shape="rect" coord="354,10,580,235" alt="购码" title="点击开始购码"/>
    <area shape="rect" coord="641,10,802,235" alt="录码" title="点击开始录码"/>
    <area shape="rect" coord="869,10,1280,235" alt="购码" title="点击购码"/>
   <area shape="rect" coord="1185,403,1583,685" alt="扫码" title="点击进入经销商扫码"/>
   </map>
</div>


  js:

document.body.onresize = ()=>{
adjust();
};

adjust();


//获取MAP中元素属性
adjust(){
let map = document.getElementById('flowChart');
var element = map.getElementsByTagName('area');
  var imgWidth = document.getElementById("flowImg").width;
for (var i = 0; i < element.length; i++) {
var item = element[i];
var oldCoords = item.getAttribute('coord');
var newCoords = adjustPosition(imgWidth, oldCoords);
item.setAttribute("coords", newCoords);
}
},
//调整MAP中坐标
adjustPosition(imgWidth, position) {
var each = position.split(",");
for (var i = 0; i < each.length; i++) {
each[i] = Math.round(parseInt(each[i]) * imgWidth / 1600).toString();//x坐标
}
return each.join(",")
}

相关文章:

  • 2021-12-15
  • 2021-12-15
  • 2022-12-23
  • 2022-02-22
  • 2021-12-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案