美文网首页
SVG 矢量绘制常见问题

SVG 矢量绘制常见问题

作者: 代小代isDelenDelen | 来源:发表于2017-05-30 20:54 被阅读109次

一.动画 

1.animateTransform与animate不同的地方

animate 可以自动动画叠加而animateTransform需要加入additive="sum"才能实现动画叠加

例如

let _animateTransform=document.createElementNS(SVG_NS,'animateTransform'); //创建动画

_animateTransform.setAttribute('attributeName','transform');//指定动画属性名称

_animateTransform.setAttribute('attributeType','XML');//指定动画属性类型

_animateTransform.setAttribute('additive','sum');// 关键 指定动画效果是否叠加 默认是 replace 替换

animateBig.setAttribute('type','scale');// transform  的属性 可以是transition rotate scale skew

animateBig.setAttribute('dur', dur);//设置持续事件

animateBig.setAttribute('from',scale); //是指初始属性

animateBig.setAttribute('to',scale*4);//设置目标属性

animateBig.setAttribute('id','big'+this.state.startCount); //指定id

animateBig.setAttribute('begin','0;small.end');//指定什么事件开始 0 表示加载后立即开始,small.end small  为另外一个动画的id  指该动画结束后再开始 可制作循环动画

animateBig.setAttribute('repeatCount','indefinite');  //自带的动画循环属性 可设置 1-indefinite

2.transform属性 

1.transform="scale(1,-1)" 表示x轴不变,y轴反转成-1

3.animateMotion(js操作animateMotion)

var circle=document.createElementNS("http://www.w3.org/2000/svg","circle");//创建运动的圆

circle.setAttributeNS(null,"cx",0);

circle.setAttributeNS(null,"cy",0);

circle.setAttributeNS(null,"r",4);

circle.setAttributeNS(null,"fill",'#9be482');

var animateMotion=document.createElementNS("http://www.w3.org/2000/svg","animateMotion");//创建动画

animateMotion.setAttributeNS(null,"dur",'6s');

animateMotion.setAttributeNS(null,"repeatCount",'indefinite');

animateMotion.setAttributeNS(null,'path',path);//设置动画path路径 或者选用下方 xlink:href指定对应的path路径

// var mPathObj = document.createElementNS("http://www.w3.org/2000/svg","mpath");

//      mPathObj.setAttribute("xlink:href",'#path');

//      animateMotion.appendChild(mPathObj);

circle.appendChild(animateMotion);

对应生成类似如下dom结构(注意不会生成一模一样,只是两种书写形式)

相关文章

  • 无标题文章

    SVG svg和canvas的区别 svg绘制的是矢量图, canvas绘制的是位图 svg使用XML来绘制图片,...

  • SVG 矢量绘制常见问题

    一.动画 1.animateTransform与animate不同的地方 animate 可以自动动画叠加而ani...

  • H5 新特性05

    SVG svg与canvas的区别 canvas绘制的是位图, svg绘制的是矢量图 canvas使用Ja...

  • HTML5

    #SVG矢量图绘制 SVG标签用于绘制矢量图。 与HTML标签相比:它们都是XML标签的衍生产物,属于平级的兄弟关...

  • SVG

    内容整理自网上! 1、什么是SVG? 2、SVG的优势: 3、绘制矢量图形 参考文档:https://develo...

  • SVG

    @(HTML5)[canvas与SVG] [TOC] 十一 、SVG HTML体系中,最常用的绘制矢量图的技术是S...

  • 前端数据可视化技术

    1、SVG SVG是一种XML语言,类似XHTML,可以用来绘制矢量图形。SVG可以通过定义必要的线和形状来创建一...

  • Android滑动卡顿问题查找与优化

    Android中绘制的原理 Android使用的绘制引擎是Skia,而App中的动画、2D绘制、SVG矢量图都是通...

  • SVG矢量图形打造不规则的自定义控件

    svg 概念 :矢量图形 SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG ...

  • iOS SVGKit的使用

    svg 可缩放的矢量图形 SVG 可伸缩矢量图形 (Scalable Vector Graphics) SVG 文...

网友评论

      本文标题:SVG 矢量绘制常见问题

      本文链接:https://www.haomeiwen.com/subject/lgnrfxtx.html