#2 基本API

2017-12-24  本文已影响10人  JamesSawyer

创建svg所需要的api

svg的命名空间为: http://www.w3.org/2000/svg

示例:

const SVG_NS = 'http://www.w3.org/2000/svg'; // 命名空间

const svg = document.createElementNS(SVG_NS, 'svg'); // 创建svg元素
document.body.appendChild(svg); // 添加到body
svg.setAttribute('width', '200');   // 设置svg的属性
svg.height('height', 200);

慕课网第一章的示例,可以参考这位小伙伴的笔记 SVGEditor.js

上一篇 下一篇

猜你喜欢

热点阅读