简介:
,允许你轻松操作SVG和定义动画。
SVG(Scalable Vector Graphics,可缩放矢量图形)是基于XML、用于描述二维矢量图形的一种图形格式。SVG由W3C制定,是一个开放标准。
,如移动、缩放、旋转、倾斜等,具体可参阅相关演示。
:
易读的简洁的语法
非常轻量,gzip压缩版只有5k
针对大小、位置、颜色等的动画元素
模块化结构,轻松扩展
各种实用插件
各种形状类型间拥有统一的API.
元素可以绑定事件,包括触摸事件
完全支持不透明蒙版
元素组
动态渐变
填充模式
完整的文档记录
使用说明:
Create a SVG document
Use the SVG() function to create a SVG document within a given html element:
var draw = SVG('canvas').size(300, 300)
var rect = (100, 100).attr({ fill: '#f06' })
The first argument can either be an id of the element or the selected element itself. This will generate the following output:
<div id="canvas">
<svg xmlns="" version="" xmlns:xlink="" width="300" height="300">
<rect width="100" height="100" fill="#f06"></rect>
</svg>
</div>
By default the svg canvas follows the dimensions of its parent, in this case #canvas:
var draw = SVG('canvas').size('100%', '100%')
Checking for SVG support
By default this library assumes the client's browser supports SVG. You can test support as follows:
if () {
var draw = SVG('canvas')
var rect = (100, 100)
} else {
alert('SVG not supported')
}
ViewBox
The viewBox attribute of an <svg> element can be managed with the viewbox() method. When supplied with four arguments it will act as a setter:
(0, 0, 297, 210)
Alternatively you can also supply an object as the first argument:
({ x: 0, y: 0, width: 297, height: 210 })
Without any arguments an instance of will be returned:
var box = ()
But the best thing about the viewbox() method is that you can get the zoom of the viewbox:
var box = ()
var zoom =
If the size of the viewbox equals the size of the svg canvas, the zoom value will be 1.
Nested svg
With this feature you can nest svg documents within
Svg.js使用手册 来自淘豆网m.daumloan.com转载请标明出处.