简体   繁体   English

更改图像映射中不同多边形的标题属性

[英]Change title attribute of different polygons in an image map

I have this image that I have mapped. 我有这个我已映射的图像。 It has many regions in the shape of polygons and on hover the region gets colored (and by colored I mean another picture). 它有许多多边形的区域,在悬停时区域变色(并且通过彩色我的意思是另一张图片)。 I have also made a custom tooltip to go with it so that on hover when it is colored a text box appears with info which stretches for more than one line. 我还制作了一个自定义工具提示,以便在悬停时,当它被着色时,会出现一个文本框,其中的信息会延伸多行。

The problem is that I cannot fathom how to mix these two together. 问题是我无法理解如何将这两者混合在一起。 Here is the code so far: 这是迄今为止的代码:

<div style="text-align:center; width:450px; margin-left:auto; "> <img id="Image-           Maps_4201211181157353" src="...Original.png" usemap="#Image-Maps_4201211181157353" border="0" width="450" height="321" alt="" title=""  /> <map id="_Image-Maps_4201211181157353" name="Image-Maps_4201211181157353">

<!--Area1--> <area shape="poly"coords="370,191,363,195,355,194,343,193,339,185,330,173,327,164,325,154,338,149,351,149,364,149,365,165,364,181," href=" " alt=""  id="1" onMouseOver="if(document.images) document.getElementById('Image-Maps_4201211181157353').src= '...Area1.png';" onMouseOut="if(document.images) document.getElementById('Image-Maps_4201211181157353').src= '...Original.png';" /> </map>

Where Original.png is the original picture and Area1.png is the region that changes color upon mouseover. 其中Original.png是原始图片,而Area1.png是鼠标悬停时改变颜色的区域。

And this is the tooltip class: 这是工具提示类:

<a class="tooltip" href="#"> Tooltip
  <span class="custom warning">
       <em>Title</em>Example text
  </span> </a>

So what I'd like is to insert the custom-made tooltip inside the map div as a title attribute for each polygonal area of the map. 所以我想要的是在地图div中插入自定义工具提示作为地图每个多边形区域的标题属性。

What you need to do is loop through the coordinates of each AREA and find the top/left or center, then using JavaScript set the position of the tooltip using position:absolute accordingly. 你需要做的是循环每个AREA的坐标并找到顶部/左边或中心,然后使用JavaScript设置工具提示的位置使用position:absolute相应。 It's easy for rectangles, but polygons will require a bit more work. 矩形很容易,但多边形需要更多的工作。

There really is no easy way to do this. 真的没有简单的方法可以做到这一点。

See: Get position of map area(html)? 请参阅: 获取地图区域的位置(html)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM