前端怎么对一张图片特定某些点进行点击事件(image-map)

图片热区技术

插入一张图片,并设置好图像的有关参数,在<img>标记中设置参数usemap="#image-map",以表示对图像地图的引用。

<map>标记设定图像地图的作用区域,并取名:image-map

分别用<area>标记针对相应位置互粉出多个矩形作用区域,并设定好链接参数href

https://www.image-map.net/

生成map代码

html代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
  </style>
  <body>
    <!-- Image Map Generated by http://www.image-map.net/ -->
    <img src="./001457Of5d7.jpg" usemap="#image-map">
    <map name="image-map">
        <area onclick="getClick('床')" target="" alt="床" title="床" href="" coords="23,111,479,911" shape="rect" >
        <area onclick="getClick('地球仪')" target="" alt="地球仪" title="地球仪" href="" coords="542,819,61" shape="circle">
        <area onclick="getClick('电脑桌')" target="" alt="电脑桌" title="电脑桌" href="" coords="629,502,1153,859" shape="rect">
    </map>
  </body>
  <script>
    function getClick(type){
      alert(type)
    }
  </script>
</html>

posted @ 2022-09-21 14:32  槑孒  阅读(1817)  评论(2)    收藏  举报