Latest web development tutorials

HTML DOM Area coords 屬性

Area 對象參考手冊 Area對象

定義和用法

coords 屬性可設置或者返回某個區域的coords 屬性值。

coords 屬性描述了圖像映射中某個可點擊區域的坐標。

提示:區域的左上角坐標0,0。

語法

areaObject.coords=value

coords 輸出可以是以下值:

描述
x1,y1,x2,y2 如果 shape 属性设置为"rect",它 指定的左上角和右下角的矩形坐标
x,y,radius 如果 shape 属性设置为"circle",它 指定圆心坐标和半径
x1,y1,x2,y2,..,xn,yn 如果 shape 属性设置为 "poly",它 指定多边形的的坐标。如果第一个和最后一个 坐标是不一样的,浏览器必须加上一个闭合多边形的坐标


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持coords 屬性


實例

實例

返回圖像映射中"Venus" 區域的的坐標:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
</head>
<body>

<img src="planets.gif" width="145" height="126" usemap="#planetmap">
<map name="planetmap">
<area id="venus" shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
<p>金星的坐标:
<script>
document.write(document.getElementById("venus").coords);
</script>
</p>

</body>
</html>

以上實例輸出結果:

金星的坐标: 124,58,8

嘗試一下»


Area 對象參考手冊 Area對象