javascript - HTML 标记中的区域蓝色轮廓?

标签 javascript jquery html css area

我正在查看 HTML 热点,并且对我在之前的 Stack Overflow 问答中找到的示例有疑问。

Previous Stack OverFlow Area Example

在“Gibberish”的第一个回答中,他提供了一个关于 JSFiddle 的有效示例。 JSFiddle Example from Gibberish

function hovIn() {
  var areaID = $(this).attr('id');
  //alert('['+areaID+']');
  if (areaID == 'CUST_1') {
    $('#myDiv').show();
  }
}

function hovOut() {
  $('#myDiv').hide();
}

$('map area').hover(hovIn, hovOut);
#num_cust1 {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  top: 60px;
  left: 180px;
}

#num_cust2 {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  top: 60px;
  left: 40px;
}

#num_cust3 {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  top: 160px;
  left: 180px;
}

#myDiv {
  display: none;
  width: 50%;
  height: 50px;
  padding: 10px;
  background-color: skyblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Instructions: Mouse over computer's monitor to see hidden DIV
<!--<img src="http://www.proprofs.com/quiz-school/upload/yuiupload/2014513384.jpg" width="400" height="400" />-->
<div id="imagemap">
  <img src="http://img716.imageshack.us/img716/8287/3ylp.jpg" width="275" height="207" usemap="#Map" border="0" />
  <map name="Map">
        <area shape="poly" coords="105,26,107,126,257,140,256,27" href="#" id="CUST_1" name="CUST:1" />
        <area shape="poly" coords="10,21,14,178,71,184,69,19" href="#" id="CUST_2" name="CUST:2" />
        <area shape="poly" coords="113,145,94,172,241,192,251,164,250,164" href="#" id="CUST_3" name="CUST:3" />
    </map>
  <p>
    <div id="myDiv">This DIV hidden unless hover over the computer's monitor</div>
  </p>
</div>
<!-- Yellow DIV ID numbers overlaid on top of computer components -->
<div id="num_cust1">1</div>
<div id="num_cust2">2</div>
<div id="num_cust3">3</div>

我理解大部分答案是如何工作的,如果我点击三个定义的多边形区域中的任何一个,它们就会以蓝色轮廓突出显示 - 但我看不到实现这一点的代码(例如点击事件).谁能解释他们如何/为什么在没有任何代码(我可以看到)的情况下显示蓝色??

显示蓝色点击区域的 Fiddle 输出屏幕截图:

1

最佳答案

ma​​p 标签用于定义客户端图像映射。图像映射是具有可点击区域的图像。

ma​​p 元素所需的名称属性与 img 的 usemap 属性相关联,并在图像和 map 之间建立关系。

ma​​p 元素包含许多 area 元素,它们定义图像映射中的可点击区域。

隐藏轮廓你可以做

map area {
  outline: none;
}
<map name="primary">
  <area shape="circle" coords="75,75,75" href="#">
  <area shape="circle" coords="275,75,75" href="#">
</map>
<img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">

使用 outine css 属性,你可以对 map 区域做很多事情。例如,你想将颜色从 blue 更改为 red 你可以做

map area{
outline-color: red;
}
<map name="primary">
  <area shape="circle" coords="75,75,75" href="#">
  <area shape="circle" coords="275,75,75" href="#">
</map>
<img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">

关于javascript - HTML 标记中的区域蓝色轮廓?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42667143/

相关文章:

javascript - 我只能从以下 Javascript 中 append 1 个卡片元素

javascript - 为什么 IE 9 中图像不通过 CSS 参数旋转?

javascript - 将不属于对话框一部分的单元格添加到表中

javascript - 如何在javascript中动态转换诸如 "select::-ms-expand"之类的css?

javascript - 如何在静态站点上动态呈现社交分享按钮的元标记?

html - 标题背景图像未涵盖所有标题内容

javascript - 从父页面向上和向下滚动 Iframe?

Javascript 合并对象数组中的重复项

javascript - 当找到表中的元素时删除行

jQuery UI 盲效果 - 从底部显示