| <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="250" height="250"> <script language="JavaScript"> <![CDATA[ function circle_click() { var circle = document.getElementById("circulo"); var raio = circle.getAttribute("r"); if (raio == 50) { circle.setAttribute("r", 100); } else { circle.setAttribute("r", 50); } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onclick="circle_click()" id="circulo" cx="125" cy="125" r="50" fill="red"/> <text id="texto" x="15" y="20" font-family="Verdana" font-size="15">SVG</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| <embed src="svg/atributo.svg" height="250" width="250"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="250" height="250"> <script language="javascript"> <![CDATA[ function circle_click() { var circle = document.getElementById("circulo"); var opacidade = circle.style.opacity; if (opacidade == 1) { circle.style.opacity = 0.3; } else { circle.style.opacity = 1; } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onclick="circle_click()" id="circulo" cx="125" cy="125" r="50" style="opacity:1" fill="red"/> <text id="texto" x="15" y="20" font-family="Verdana" font-size="15">SVG</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| <embed src="svg/opacidade.svg" height="250" width="250"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="250" height="250"> <script language="JavaScript"> <![CDATA[ function circle_click() { var txt = document.getElementById("texto"); var texto = txt.firstChild.nodeValue; if (texto == "SVG") { txt.firstChild.nodeValue = "Teste"; } else { txt.firstChild.nodeValue = "SVG"; } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onclick="circle_click()" id="circulo" cx="125" cy="125" r="50" fill="red"/> <text id="texto" x="15" y="20" font-family="Verdana" font-size="15">SVG</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| <embed src="svg/value.svg" height="250" width="250"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="250" height="250"> <style type="text/css"> <![CDATA[ .vermelho { fill: red; stroke: blue; stroke-width: 5; } .azul { fill: blue; stroke: green; stroke-width: 10; } ]]> </style> <script language="JavaScript"> <![CDATA[ function circle_click() { var circle = document.getElementById("circulo"); var classe = circle.className.baseVal; if (classe == "vermelho") { circle.className.baseVal = "azul"; } else { circle.className.baseVal = "vermelho"; } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onclick="circle_click()" id="circulo" cx="125" cy="125" r="50" fill="red"/> <text id="texto" x="15" y="20" font-family="Verdana" font-size="15">SVG</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| <embed src="svg/classe.svg" height="250" width="250"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="250" height="250"> <style type="text/css"> <![CDATA[ .visivelX { visibility: visible; } .invisivelX { visibility: hidden; } ]]> </style> <script language="JavaScript"> <![CDATA[ function circle_click() { var circle = document.getElementById("circulo"); var classe = circle.className.baseVal; if (classe == "visivelX") { circle.className.baseVal = "invisivelX"; } else { circle.className.baseVal = "visivelX"; } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onclick="circle_click()" cx="125" cy="125" r="50" fill="red"/> <circle id="circulo" class="visivelX" cx="25" cy="25" r="20" fill="green"/> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| <embed src="svg/invisivel.svg" height="250" width="250"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
|
<svg function makeShape(evt) { |
| <embed src="svg/funcao.svg" height="110" width="310"
type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
Eventos
OnClick
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250"> <script language="JavaScript"> <![CDATA[ function circle_click() { var circle = document.getElementById("circulo"); var raio = circle.getAttribute("r"); if (raio == 50) { circle.setAttribute("r", 100); } else { circle.setAttribute("r", 50); } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onclick="circle_click()" id="circulo" cx="125" cy="125" r="50" fill="red"/> <text id="texto" x="15" y="20" font-family="Verdana" font-size="15">SVG</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| Resultado: |
MouseOver MouseOut
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250"> <script language="JavaScript"> <![CDATA[ function circle_mouse(valor) { var texto = document.getElementById("texto"); if(valor == true){ texto.firstChild.nodeValue = "Mouse Over"; } else { texto.firstChild.nodeValue = "Mouse Out"; } } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <circle onmouseover="circle_mouse(true)" onmouseout="circle_mouse(false)" id="circulo" cx="125" cy="125" r="50" fill="red"/> <text id="texto" x="15" y="20" font-family="Verdana" font-size="15">SVG</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no circulo</text> </svg> |
| Resultado: |
Mousemove
| <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250"> <script language="JavaScript"> <![CDATA[ function rect_mouse(evt) { var texto1 = document.getElementById("texto1"); var texto2 = document.getElementById("texto2"); texto1.firstChild.nodeValue = "screenX="+evt.screenX+", screenY="+evt.screenY; texto2.firstChild.nodeValue = "clientX="+evt.clientX+", clientY="+evt.clientY; } ]]> </script> <rect x="1" y="1" width="248" height="248" fill="none" stroke="blue"/> <rect x="75" y="75" width="100" height="100" onmousemove="rect_mouse(evt)" fill="red"/> <text id="texto1" x="15" y="20" font-family="Verdana" font-size="15">screen</text> <text id="texto2" x="15" y="40" font-family="Verdana" font-size="15">client</text> <text x="15" y="240" font-family="Verdana" font-size="15">Clique no quadrado</text> </svg> |
| Resultado: |
Teclado
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250"> var typeInitialized = false; function typeText(evt) { if (evt.charCode) { var texto1 = document.getElementById("texto1"); ]]> </script> |
| <embed src="svg/tecla.svg" height="250" width="250" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
Clicar e Arrastar
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250" onmousedown="desenhar_down(evt)" onmousemove="desenhar_move(evt)" onmouseup="desenhar_up(evt)"> |
| <embed src="svg/desenhar.svg" height="250" width="250" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" ></embed> |
| Resultado: |
| XML | CSS | Javascript | jQuery | JSON |