1
0
mirror of https://gitee.com/tawords/tawords-docs synced 2025-01-11 20:08:16 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
tawords-docs/docs/manual/6. 【清单 ToDo】/随笔记/html map标签.md

113 lines
3.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

https://www.w3school.com.cn/html5/tag_map.asp
```html
<img src="planets.gif" alt="Planets" usemap ="#planetmap" />
<map name="planetmap">
<area shape ="rect" coords ="0,0,110,260" href ="sun.htm" alt="Sun" />
<area shape ="circle" coords ="129,161,10" href ="mercur.htm" alt="Mercury" />
<area shape ="circle" coords ="180,139,14" href ="venus.htm" alt="Venus" />
</map>
```
http://www.divcss5.com/html5/h54844.shtml
```html
首先让我们来看一下htmlmap标签是什么
  htmlmap标签:定义一个客户端图像映射。图像映射image-map指带有可点击区域的一幅图像。
  定义map
  <mapid="im_map" name="im_map">
  <areashape="rect" coords="0,0,100,100"href="url.html"/>
  </map>
  map标签定义maparea标签定义可点击的热点area属性;
  shape定义热点形状可选参数rect(矩形)、circle(圆形)、poligon(自定义形状)。
  coords定义形状路径;
  当shape=rect时四个数字依次为起点X、起点Y、终点X、终点Y
  当shape=circle时三个数字依次为中心点X、中心点Y、半径
  当shape=poligon时可定义多个路径点依次为起点X、起点Y、路径1X、路径1Y、路径2X、路径2Y......
  href定义点击跳转的地址。
  htmlmap标签必需的属性
  idunique_name为map标签定义唯一的名称。
  htmlmap标签可选的属性
  namemapname为image-map规定的名称。
  map标签在HTML中的结构
  1、coords的对应坐标不用变只需在JS里面改变其比例就OK
  <divclass="map_img">
  <imgclass="mapImg" usemap="mapName"src="isphoto/abc.png"alt=""style="width:450px">
  <mapname="mapName">
  <!--方形区域写法-->
  <!--<areashape="rect"coords="605,250,660,305"target="_blank"href="javascript:alert(1);"alt=""/>-->
  <areashape="circle" coords="633,276,28"target="_blank"href="javascript:alert('汽车图标');"alt=""/>
  </map>
  </div>
  2、如果有多张图片一张图片对应一个mapclass不用变改变map的name值和对应的usemap值就好。name=usemap他们俩是一对CP哦不要分开它们给他们一样的值。
  <divclass="map_img">
  <imgclass="mapImg" usemap="mapName"src="isphoto/abc.png"alt=""style="width:450px">
  <mapname="mapName">
  <areashape="circle" coords="633,276,28"target="_blank"href="javascript:alert('汽车图标');"alt=""/>
  </map>
  <!--一张图片对应一个name和usemap-->
  <imgclass="mapImg" usemap="mapName2"src="isphoto/abc.png"alt=""style="width:450px">
  <mapname="mapName2">
  <areashape="circle" coords="633,276,28"target="_blank"href="javascript:alert('第二张图的汽车图标');"alt=""/>
  </map>
  </div>
  html<map>标签常用在为图像的某区域添加超链接!
  用法如下:
  <imgsrc="planets.gif" alt="无法显示此图像" usemap="#planetmap"/>
  <mapid="planetmap" name="planetmap">
  <areashape="rect" coords="0,0,82,126"href="sun.htm"alt="Sun"/>
  <areashape="circle" coords="90,58,3"href="mercur.htm"alt="Mercury"/>
  <areashape="circle" coords="124,58,8"href="venus.htm"alt="Venus"/>
  </map>
  usemap属性获取<map>标签信息,<area>标签定义一个链接区域shape属性定义区域形状coords属性定义链接区域的起点坐标和终点坐标
  注释area元素永远嵌套在map元素内部。area元素可定义图像映射中的区域。
  注释:<img>中的usemap属性可引用<map>中的id或name属性取决于浏览器所以我们应同时向<map>添加id和name属性。
```