¿¹Á¦ 1)
<svg width="6cm" height="5cm" viewBox="0 0 600 500"> <script type="text/ecmascript"> <![CDATA[ function circle_click(evt) { var circle = evt.target; var currentRadius = circle.getAttribute("r"); if (currentRadius == 100) circle.setAttribute("r", currentRadius*2); else circle.setAttribute("r", currentRadius*0.5); } ]]> </script> <rect x="1" y="1" width="598" height="498" fill="#FFFF88" /> <circle onclick="circle_click(evt)" cx="300" cy="225" r="100" fill="red"/> <text x="300" y="480" font-family="Verdana" font-size="35" text-anchor="middle"> Click on circle to change its size </text> </svg> |
|
¿¹Á¦ 2)
<svg width="6cm" height="5cm" viewBox="0 0 600 500"> <script type="text/ecmascript"> <![CDATA[ function circle_over(evt) { var circle = evt.target; var currentStroke = circle.getAttribute("stroke"); if (currentStroke == "none") circle.setAttribute("stroke", "blue"); } function circle_out(evt) { var circle = evt.target; var currentStroke = circle.getAttribute("stroke"); if (currentStroke != "none") circle.setAttribute("stroke", "none"); } ]]> </script> <rect x="1" y="1" width="598" height="498" fill="#FFFF88"/> <circle onmouseover="circle_over(evt)" onmouseout="circle_out(evt)" cx="300" cy="225" r="100" stroke="none" fill="red"/> <text ...> Move mouse over/out the circle </text> </svg> |
|
¿¹Á¦) »õ·Î¿î °´Ã¼ ¸¸µé±â
<svg width="5cm" height="5cm" viewBox="0 0 500 500" onload="make_shape(evt)"> <script type="text/ecmascript"> <![CDATA[ var style; function make_circle(evt) { var SVGDoc = evt.getTarget().getOwnerDocument(); var SVGRoot = SVGDoc.getDocumentElement(); rect = SVGDoc.createElement("rect"); rect.setAttribute("x", 100); rect.setAttribute("y", 100); rect.setAttribute("width", 300); rect.setAttribute("height", 300); style = rect.getStyle(); style.setProperty("fill", "red"); rect.addEventListener("click", change_color, false); SVGRoot.appendChild(rect); } function change_color() { var fill = style.getPropertyValue("fill"); if (fill == "red") style.setProperty("fill", "blue"); else style.setProperty("fill", "red"); } ]]> </script> </svg> |
<script> <![CDATA[ var rect; function make_circle(evt) { var SVGDoc = ... ... rect.setAttribute("height", 300); rect.setAttribute("fill", "red"); rect.addEventListener( ...); ... } function change_color() { var fill = rect.getAttribute("fill"); if (fill == "red") rect.setAttribute("fill", "blue"); else rect.setAttribute("fill", "red"); } ]]> </script> |
¿¹Á¦) ÀÖ´Â °´Ã¼ ¹Ù²Ù±â
<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>¿¹Á¦) °´Ã¼ ¿òÁ÷À̱â
<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>
¿¹Á¦)
<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>