书签 分享 收藏 举报 版权申诉 / 25

类型Svgjs使用手册.docx

  • 文档编号:2259172
  • 上传时间:2022-10-28
  • 格式:DOCX
  • 页数:25
  • 大小:30.55KB

Bydefaultthesvgcanvasfollowsthedimensionsofitsparent,inthiscase #canvas:

vardraw=SVG('canvas').size('100%','100%')

CheckingforSVGsupport

Bydefaultthislibraryassumestheclient'sbrowsersupportsSVG.Youcantestsupportasfollows:

if(SVG.supported){

vardraw=SVG('canvas')

varrect=draw.rect(100,100)

}else{

alert('SVGnotsupported')

}

ViewBox

The viewBox attributeofan  elementcanbemanagedwiththe viewbox() method.Whensuppliedwithfourargumentsitwillactasasetter:

draw.viewbox(0,0,297,210)

Alternativelyyoucanalsosupplyanobjectasthefirstargument:

draw.viewbox({x:

0,y:

0,width:

297,height:

210})

Withoutanyargumentsaninstanceof SVG.ViewBox willbereturned:

varbox=draw.viewbox()

Butthebestthingaboutthe viewbox() methodisthatyoucangetthezoomoftheviewbox:

varbox=draw.viewbox()

varzoom=box.zoom

Ifthesizeoftheviewboxequalsthesizeofthesvgcanvas,thezoomvaluewillbe1.

Nestedsvg

Withthisfeatureyoucannestsvgdocumentswithineachother.Nestedsvgdocumentshaveexactlythesamefeaturesasthemain,top-levelsvgdocument:

varnested=draw.nested()

varrect=nested.rect(200,200)

Thisfunctionalityrequiresthenested.jsmodulewhichisincludedinthedefaultdistribution.

SVGdocument

Svg.jsalsoworksoutsideoftheHTMLDOM,insideanSVGdocumentforexample:

xmlversion="1.0"encoding="utf-8"?

>

//www.w3.org/2000/svg"xmlns:

xlink="http:

//www.w3.org/1999/xlink"version="1.1">

href="svg.min.js">

[CDATA[

vardraw=SVG('viewport')

draw.rect(100,100).animate().fill('#f03').move(100,100)

]]>

Elements

Rect

Rectshavetwoarguments,their width and height:

varrect=draw.rect(100,100)

Ellipse

Ellipses,likerects,havetwoarguments,their width and height:

varellipse=draw.ellipse(200,100)

Circle

Theonlyargumentnecessaryforacircleisthediameter:

varcircle=draw.circle(100)

Notethatthisgeneratesan  elementinsteadofa .Thischoicehasbeenmadetokeepthesizeofthelibrarydown.

Line

Thelineelementalwaystakesfourarguments, x1, y1, x2 and y2:

varline=draw.line(0,0,100,150).stroke({width:

1})

Polyline

Thepolylineelementdefinesasetofconnectedstraightlinesegments.Typically,polylineelementsdefineopenshapes:

//polyline('x,yx,yx,y')

varpolyline=draw.polyline('0,0100,5050,100').fill('none').stroke({width:

1})

Polylinestringsconsistofalistofpointsseparatedbyspaces:

 x,yx,yx,y.

Asanalternativeanarrayofpointswillworkaswell:

//polyline([[x,y],[x,y],[x,y]])

varpolyline=draw.polyline([[0,0],[100,50],[50,100]]).fill('none').stroke({width:

1})

Polylinescanbeupdatedusingthe plot() method:

polyline.plot([[0,0],[100,50],[50,100],[150,50],[200,50]])

The plot() methodcanalsobeanimated:

polyline.animate(3000).plot([[0,0],[100,50],[50,100],[150,50],[200,50],[250,100],[300,50],[350,50]])

Polygon

Thepolygonelement,unlikethepolylineelement,definesaclosedshapeconsistingofasetofconnectedstraightlinesegments:

//polygon('x,yx,yx,y')

varpolygon=draw.polygon('0,0100,5050,100').fill('none').stroke({width:

1})

Polygonstringsareexactlythesameaspolylinestrings.Thereisnoneedtoclosetheshapeasthefirstandlastpointwillbeconnectedautomatically.

Path

Thepathstringissimilartothepolygonstringbutmuchmorecomplexinordertosupportcurves:

//path('pathdata')

varpath=draw.path('M10,20L30,40')

Formoredetailsonpathdatastrings,pleaserefertotheSVGdocumentation:

http:

//www.w3.org/TR/SVG/paths.html#PathData

Notethatpathswillalwaysbepositionedatx=0,y=0oncreation.Thisistomaketheunified move() apipossible.Svg.jsassumesyouarecreatingapathtomoveitafterwards.Ifyouneedtoconstantl

配套讲稿:

如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

特殊限制:

部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

关 键  词:
Svgjs 使用手册
提示  冰豆网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:Svgjs使用手册.docx
链接地址:https://www.bdocx.com/doc/2259172.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2008-2022 冰点文档网站版权所有

经营许可证编号:鄂ICP备2022015515号-1

收起
展开