Á¦12/11Àå. Script, Interactivity & Linking

Javascript °³¿ä

À̺¥Æ® Çڵ鸵

<script> ¿ä¼Ò

SVG À̺¥Æ® ó¸® (Á¦11Àå)

¿¹Á¦) ÀÖ´Â °´Ã¼ ¹Ù²Ù±â  
<svg width="5cm" height="5cm" viewBox="0 0 500 500">

  <script type="text/ecmascript"> <![CDATA[
    function change_color(evt) {
      var SVGDoc = evt.getTarget().getOwnerDocument();
      var rect = SVGDoc.getElementById("rect1");
      var style = rect.getStyle();
      var fill = style.getPropertyValue("fill"); 
      if (fill == "red")  style.setProperty("fill", "green");
      else  style.setProperty("fill", "red");
    }
 ]]> </script>

 <rect  id="rect1" onclick="change_color(evt)" 
      x="100" y="100" width="300" height="300" 
      style="fill:red"/>

</svg>

  function change_color(evt) {
    var rect = evt.target;
    var fill = rect.getAttribute("fill"); 
    if (fill == "red")
        rect.setAttribute("fill", "green");
    else  rect.setAttribute("fill", "red");
  }
<rect  onclick="change_color(evt)"
      x="100" ...   fill="red"/>

¿¹Á¦) °´Ã¼ ¿òÁ÷À̱â
<svg width="600" height="100">

  <script type="text/ecmascript"> <![CDATA[
     var posX=0, posY=0;

     function rect_pos(evt) {
        var dx = evt.clientX;
        var dy = evt.clientY; 
        alert("mouse position: "+dx+", "+dy);
     }

     function rect_move(evt) {
        if (posX==0) return;
        var rect = evt.target;
        var dx = evt.clientX-posX;
        var dy = evt.clientY-posY;
        var rx = eval(rect.getAttribute("x"))+dx; 
        var ry = eval(rect.getAttribute("y"))+dy;
        rect.setAttribute("x", rx);
        rect.setAttribute("y", ry); 
        posX += dx; posY += dy;
     }
     function rect_down(evt) {
        var rect = evt.target;
        posX = evt.clientX;
        posY = evt.clientY; 
        rect.setAttribute("stroke", "blue");
     }
     function rect_up(evt) {
        var rect = evt.target;
        rect.setAttribute("stroke", "none");
        posX = 0; posY = 0;
     }

  ]]> </script>

  <rect onclick="rect_pos(evt)"  x="0" y="0" 
      width="600" height="100" fill="#AAFFAA"/>

  <rect onmousedown="rect_down(evt)"  
       onmousemove="rect_move(evt)" 
       onmouseup="rect_up(evt)"
       x="30" y="30" width="40" height="40"  
       stroke-width='2' fill="#00CC00"/>
</svg>

Æ÷ÀÎÅÍ À̺¥Æ®, Ä¿¼­ (Á¦11Àå)

¸µÅ© (Linking)

¿¹Á¦)
<svg width="5cm" height="3cm" viewBox="0 0 5 3">
   <rect x=".01" y=".01" width="4.98" height="2.98" 
        fill="none" stroke="blue" stroke-width=".05"/>
   <a xlink:href="http://www.w3c.org">
       <rect x=".4" y=".5" width="2" height="2" fill="red" />
   </a>
   <a xlink:href="Example/s10-clip01.svg">
       <ellipse cx="3.7" cy="1.5" rx="1" ry="1" fill="green" />
   </a>
</svg>