JavaScript Reference/Javascript Properties/coords — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:21, 26 мая 2010

"coords" Example

<!-- 
Example revised from 
The Web Programmer"s Desk Reference
by Lazaro Issi Cohen and Joseph Issi Cohen 
ISBN: 1593270119
Publisher: No Starch Press 2004
-->    
<html>
<head>
<script language="JavaScript">
    function function1() {
        document.all.area1.coords = "0, 0, 100, 50";
    }
    function function2() {
        document.all.area2.coords = "100, 0, 200, 50"; 
        document.all.area2.noHref = "true";
    }
    function function3() {
        document.all.area3.coords = "0, 50, 100, 100";
    }
    function function4() {
        document.all.area4.coords = "100, 50, 200, 100";
    }
    function function5() {
        document.getElementById("area1").coords = "0, 0, 0, 0";
        document.getElementById("area2").coords = "0, 0, 0, 0";
        document.getElementById("area3").coords = "0, 0, 0, 0";
        document.getElementById("area4").coords = "0, 0, 0, 0";
    }
</script>
</head>
<body>
<img src="yourimage.gif" id="myImg" alt="" width="200" height="100" usemap="#myMap2"> 
<map name="myMap2"> 
    <area id="area1" 
          shape="rect" 
          href="http://www.wbex.ru" 
          alt="wbex.ru" 
          onClick="return false">
    <area id="area2" 
          shape="rect" 
          href="http://www.wbex.ru" nohref="true" 
          alt="wbex.ru home page" 
          onClick="return false">
    <area id="area3" 
          shape="rect" 
          href="http://www.wbex.ru" 
          alt="wbex home page" 
          onClick="return false">
    <area id="area4" 
          shape="rect" 
          href="http://www.wbex.ru" 
          alt="wbex.ru" 
          onClick="return false">
</map>
<br>
<input type="button" value="Make area 1 active" onClick="function1();">
<input type="button" value="Make area 2 active" onClick="function2();">
<input type="button" value="Make area 3 active" onClick="function3();">
<input type="button" value="Make area 4 active" onClick="function4();">
<button onclick="function5();">Restore areas to inactive</button>
<button onclick="alert(myImg.isMap);">IS MAP</button>
<button onclick="alert(area2.noHref);">noHref for Area 2</button>
</body>
</html>



"coords" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |<a>                             <area>                        |
+----------------+--------------------------------------------------------------+



"coords" Syntax and Note

Note:
Read and write property. 
Sets the the element clickable region coordinates.
    
Syntax:
    
document.getElementById("elementID").coords = value
document.all.elementID.coords = value // IE only

Values depend on the shape attribute"s value:
shape = circ or circle                 x, y (coordinates of the center), r (radius).
shape = rect or rectangle              x1, y1 (coordinates of the upper-left corner), 
                                       x2, y2 (coordinates of the lower-right corner).
shape = poly or polygon                x1, y1, x2, y2, x3, y3, . . . 
                                       pairs of coordinates for each vertex of the polygon.