将鼠标悬停在图像的一部分上时的工具提示

Tooltips when hovering over part of an image

本文关键字:一部分 工具提示 图像 鼠标 悬停      更新时间:2023-09-26

我在html.php页面上有一个大图像,我想知道如何在悬停时指定图像的部分以显示不同的工具提示。

编辑:我在另一篇文章中发现了这个代码,我如何让它显示工具提示而不是警报?如何指定一个以上的悬停区域?

<html>
<head>
<script language="JavaScript">
function getDetails(obj){
  clickX = window.event.x-obj.offsetLeft;
  clickY = window.event.y-obj.offsetTop;
  if((clickX>=100&&clickX<=200)&&(clickY>=100&&clickY<=200))
  {
    alert(" You are between (100,100) And (200,200) of the Image");
  } 
}
</script>
</head>
<body>
  <img src="image.jpg" onMousemove="getDetails(this)" id="myimg" height="500" width="500" />
</body>
</html>

抱歉,我还在学习这个网站的工作原理。提前感谢!

使用HTML地图标记,然后为每个区域定义一个标题。

<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
  <area shape="rect" coords="0,0,82,126" href="sun.htm" title="Sun">
  <area shape="circle" coords="90,58,3" href="mercur.htm" title="Mercury">
  <area shape="circle" coords="124,58,8" href="venus.htm" title="Venus">
</map>