随身笔记
随身笔记

svg animate 动画

<svg> //相当于一个让舞台是svg能展示效果的区域
viewBox=”280,80,20,20″ //起点x轴为280,y轴80,宽20,高20的区域在svg中截图并且铺满svg

<svg width=”400″ height=”300″ viewBox=”0,0,40,30″ style=”border:1px solid #cd0000;”></svg>
viewport与preserveaspectratio
http://www.zhangxinxu.com/wordpress/2014/08/svg-viewport-viewbox-preserveaspectratio/
http://www.drawsvg.org/ svg在线绘图
http://editor.method.ac/

 

svg css属性
fill: orange //填充颜色
stroke: black //边框颜色
stroke-width: 3 //边框大小
stroke-dasharray: 10, 5 //虚线间隔
stroke-opacity: //表示描边透明度

stroke-linecap //表示描边端点表现方式stroke-linejoin
stroke-linejoin //表示描边转角的表现方式
stroke-miterlimit
http://www.zhangxinxu.com/wordpress/2014/04/animateion-line-drawing-svg-path-%E5%8A%A8%E7%94%BB-%E8%B7%AF%E5%BE%https://css-tricks.com/guide-svg-animations-smil/84/
svg animate简单动画

 

<set attributeName=”x” attributeType=”XML” to=”60″ begin=”3s” />
3秒后 沿X轴移动到 60px位置

<set> //可以在特定时间之后修改某个属性值(也可以是CSS属性值)
<animateColor> //废弃<animate>可以实现它的效果
<animateTransform> //跟css的Transform一样
<animateMotion> //让SVG各种图形沿着特定的path路径运动
<animate>
—————————————————————–

<set> 例子:
<text font-family=”microsoft yahei” font-size=”120″ y=”160″ x=”160″>

<set attributeName=”x” attributeType=”XML” to=”60″ begin=”3s” /> //3秒<text>X值设置为60
</text>

—————————————————————–

<animateTransform> 例子:

<rect>
<animateTransform
attributeType=”xml” //开始声明xml类型,如果不声明svg会自动匹配(可选)
attributeName=”transform” type=”rotate” //声明动画属性是rotate
from=”0″ to=”90″ //0deg到90deg
begin=”0″ dur=”5s” //过渡时间为5s
fill=”freeze”
/>
</rect>
——————————————————————
<animateMotion> 例子:
<text font-family=”microsoft yahei” font-size=”40″ x=”0″ y=”0″ fill=”#cd0000″>马
<animateMotion path=”M10,80 q100,120 120,20 q140,-50 160,0″ begin=”0s” dur=”3s” rotate=”auto” repeatCount=”indefinite”/>
</text>

<path d=”M10,80 q100,120 120,20 q140,-50 160,0″ stroke=”#cd0000″ stroke-width=”2″ fill=”none” />
—————————————————————-

<animate> 效果组合例子:

 

<svg width=”320″ height=”200″ xmlns=”http://www.w3.org/2000/svg”>
<text font-family=”microsoft yahei” font-size=”120″ y=”160″ x=”160″>马
<animate attributeName=”x” from=”160″ to=”60″ begin=”0s” dur=”3s” repeatCount=”indefinite” />
<animate attributeName=”opacity” from=”1″ to=”0″ begin=”0s” dur=”3s” repeatCount=”indefinite” />
</text>
</svg>
—————————————————————
animate 属性

attributeName = //要变化的元素属性名称
attributeType = “CSS | XML | auto” //用来表明attributeName属性值的列表,要写css还是写svg,例如css是style=”height:100px”,XML是height=100
from = //
to = //
begin= //
dur= //
calcMode= //
repeatCount= // 动画执行次数
repeatDur= //重复动画的总时间
fill= // 动画结束后是否保持结束后的状态

svg

 

https://css-tricks.com/guide-svg-animations-smil/

http://www.htmleaf.com/ziliaoku/qianduanjiaocheng/201506262114.html

 

<svg width="500" height="350" viewBox="0 0 500 350">
  <path id="motionPath" fill="none" stroke="#000000" stroke-miterlimit="10" d="M202.4,58.3c-13.8,0.1-33.3,0.4-44.8,9.2
    c-14,10.7-26.2,29.2-31.9,45.6c-7.8,22.2-13.5,48-3.5,70.2c12.8,28.2,47.1,43.6,68.8,63.6c19.6,18.1,43.4,26.1,69.5,29.4
    c21.7,2.7,43.6,3.3,65.4,4.7c19.4,1.3,33.9-7.7,51.2-15.3c24.4-10.7,38.2-44,40.9-68.9c1.8-16.7,3.4-34.9-10.3-46.5
    c-9.5-8-22.6-8.1-33.2-14.1c-13.7-7.7-27.4-17.2-39.7-26.8c-5.4-4.2-10.4-8.8-15.8-12.9c-4.5-3.5-8.1-8.3-13.2-11
    c-6.2-3.3-14.3-5.4-20.9-8.2c-5-2.1-9.5-5.2-14.3-7.6c-6.5-3.3-12.1-7.4-19.3-8.9c-6-1.2-12.4-1.3-18.6-1.5
    C222.5,59,212.5,57.8,202.4,58.3"/>
  <g id="car" transform="translate(-234.4, -182.8)">
      <path d="M234.4,182.8c-3.5,0-6.4,2.9-6.4,6.4c0,3.5,2.9,6.4,6.4,6.4c3.5,0,6.4-2.9,6.4-6.4C240.8,185.6,238,182.8,234.4,182.8z"/>
      <circle cx="234.4" cy="189.2" r="2.8"/>
      <path d="M263,182.8c-3.5,0-6.4,2.9-6.4,6.4c0,3.5,2.9,6.4,6.4,6.4c3.5,0,6.4-2.9,6.4-6.4C269.4,185.6,266.6,182.8,263,182.8z"/>
      <circle cx="263" cy="189.2" r="2.8"/>
      <path d="M275,171.4c-2.8-0.7-5.2-3-6.3-5.1l-3.9-7.4c-1.1-2.1-3.9-3.8-6.3-3.8h-22.6c-2.4,0-5,1.8-5.7,4.1l-2.4,7
          c-0.2,0.9-1.8,5.5-5,5.5c-2.4,0-5,3.1-5,5.5v8.2c0,2.4,1.9,4.3,4.3,4.3h4.5c0-0.2,0-0.3,0-0.5c0-4.3,3.5-7.8,7.8-7.8
          c4.3,0,7.8,3.5,7.8,7.8c0,0.2,0,0.3,0,0.5h13.1c0-0.2,0-0.3,0-0.5c0-4.3,3.5-7.8,7.8-7.8s7.8,3.5,7.8,7.8c0,0.2,0,0.3,0,0.5h8.1
          c2.4,0,4.3-1.9,4.3-4.3v-6.5C283.2,172,277.3,172,275,171.4z"/>
      <path d="M241.8,170.3h-12.5c0.7-1.1,1.1-2.2,1.2-2.6l2-5.9c0.6-1.9,2.8-3.5,4.8-3.5h4.5V170.3z"/>
      <path d="M246.1,170.3v-12h10.4c2,0,4.4,1.5,5.3,3.3l3.3,6.3c0.4,0.8,1.1,1.7,2,2.4H246.1z"/>
  </g>
  <animateMotion
           xlink:href="#car"
           dur="3s"
           begin="0s"
           fill="freeze"
           repeatCount="indefinite">
    <mpath xlink:href="#motionPath" />
  </animateMotion>
</svg>        

 

 

随身笔记

svg animate 动画
<svg> //相当于一个让舞台是svg能展示效果的区域 viewBox="280,80,20,20" //起点x轴为280,y轴80,宽20,高20的区域在svg中截图并且铺满svg <svg width="400" height="300" …
扫描二维码继续阅读
2015-06-18