7007.svg用法

1 svg 相关知识点

1.1 参考原文网页链接

https://www.zhangxinxu.com/wordpress/2014/06/deep-understand-svg-path-bezier-curves-command/

https://www.cnblogs.com/fanlinqiang/p/11826143.html

1.2 摘录部分知识点

在这里插入图片描述

在这里插入图片描述

1.3 js控制svg变化 参考他人的代码

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>使用js控制svg的示例</title>
    <script type="text/javascript" src="jquery.min.js">  </script>
</head>
<body>
    <script type="text/javascript"  defer="true" > 
        function member(id, color) {
                this.id = id;
                this.color = color;
            }
            var big_table = new Array();
            big_table[0] = new member("aaa0","#FF0000"); //svg的元素的id
            big_table[1] = new member("aaa1","#99FF00");
            big_table[2] = new member("aaa2","#0000FF");
            big_table[3] = new member("aaa3","#9900FF");
            
            function color_map_init() {
                var map = document.getElementById('map');
                    console.log("map:", map);
                    var svg_document = map.contentDocument;

                    console.log("svg_document:", svg_document);
                    

                    if (svg_document == null) {
                    alert("重写加载");
                    time = setTimeout("Inital()", 300);  
                    } else {
                    clearTimeout(time);
                    }

                    for (var iii in big_table) {
                        obj = big_table[iii].id;
                        console.log("obj:", obj);
                        this_color = big_table[iii].color;

                        this_obj = svg_document.getElementById(obj);
                        this_obj.setAttribute("style", "fill:" + this_color);
                    }
               
            }
            
            function color_map(iii,new_color) {
                var map = document.getElementById('map');
                var svg_document = map.contentDocument;



                //this_obj = svg_document.getElementById("a1");//objstr
                obj = big_table[iii];
                this_obj = svg_document.getElementById(obj.id);
                this_obj.setAttribute("style", "fill:" + new_color);
            }
        
        </script>

    <input type="button" value="初始化init" onclick="color_map_init();">
    <input type="button" value="按钮1" onclick="color_map(0,'#FFFF00');">
    <input type="button" value="按钮2" onclick="color_map(1,'#FFFF00');">
    <input type="button" value="按钮3" onclick="color_map(2,'#FFFF00');">
    <input type="button" value="按钮4" onclick="color_map(3,'#FFFF00');">
    
    <div style="position:absolute;left:0px; top:60px;border:solid 1px;">
    <!-- <object id="map" type="image/svg+xml" data="1.svg" width="800" height="700"></object> -->
    <embed id="map" width="800px" height="600px" type="image/svg+xml" src="1.svg" />
    </div>
   
</body>

</html>

svg 图片代码如下

<?xml version="1.0" standalone="no"?> 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" > 
<circle cx="100" cy="100" r="40" fill="#00FFFF" id="aaa0"/> 
<circle cx="200" cy="100" r="40" fill="#00FF00" id="aaa1"/> 

<circle cx="100" cy="200" r="40" fill="#FF00FF" id="aaa2"/> 
<circle cx="200" cy="200" r="40" fill="#ff0000" id="aaa3"/> 
</svg> 

代码只有在服务器上,才能生效,本地测试时,出错误 contentDocument 为null 导致

在这里插入图片描述

1.4 svg 中标签的具体含义

g 标签属于容器类标签,将多个标签整合到一起
line 线标签
在这里插入图片描述

在这里插入图片描述

1.5 操作svg的js库

目前查询到的操作js库有两个 一个为 svg.js ,另外一个 d3.js库

1.5.1 svg.js库的安装

Bower:

bower install svg.js

Node:

npm install svg.js
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

guangshui516

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值