zoukankan      html  css  js  c++  java
  • javascript 动态创建SVG对象

       <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                <html xml:lang="en"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:svg="http://www.w3.org/2000/svg">
                <head>
                <title>XHTML example for creating circles dynamically
                by clicking a button</title>
                <style type="text/css"><![CDATA[
                circle {
                fill: lime;
                stroke: black;
                stroke-width: 0.2cm;
                }
                ]]></style>
                <script type="application/javascript"><![CDATA[
                function create_circle()
                {
                var svg = document.getElementById('diagram');
                var cx = Math.random()*10;
                var cy = Math.random()*4;
                var r = Math.round(Math.random()*4);
                circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle')
                circle.setAttribute('cx', cx+'cm')
                circle.setAttribute('cy', cy+'cm')
                circle.setAttribute('r', r+'cm')
                svg.appendChild(circle)
                }
                ]]></script>
                </head>
                <body>
                <svg:svg id='diagram' version="1.1" width="600" height="220">
                <svg:title>Create circles dynamically</svg:title>
                </svg:svg>
                <button onclick="create_circle();">Create circle</button>
                </body>
                </html>
  • 相关阅读:
    Objective-c Category(类别)
    协议(porotocol)
    类的通用格式
    objective-c 强大的布尔类型
    C 语言函数指针
    c while 循环
    jQuery的deferred对象详解
    exploring the http Object
    div+css定位position详解
    如何给变量取个简短且无歧义的名字
  • 原文地址:https://www.cnblogs.com/lxiang/p/2993084.html
Copyright © 2011-2022 走看看