svg线条动画基础
来源:互联网 发布:哔哩哔哩视频制作软件 编辑:程序博客网 时间:2024/04/28 10:43
先介绍一个Stroke的几个属性:
stroke
表示描边颜色。一般有如下类型值:none
,currentColor
,<color>
.none
表示没有颜色,<color>
就是常规的颜色值。currentColor
继承父标签的color
颜色值。stroke-width
表示描边的粗细。stroke-linecap
表示描边端点表现方式。可用值有:butt
,round
,square
,inherit
. 表现如下图:stroke-linejoin
表示描边转角的表现方式。可用值有:miter
,round
,bevel
,inherit
. 表现如下图:stroke-miterlimit
表示描边相交(锐角)的表现方式。默认大小是4
. 什么斜角转斜面的角度损耗之类的意思,值越大,损耗越小。stroke-dasharray
表示虚线描边。可选值为:none
,<dasharray>
,inherit
. 其中,none
表示不是虚线;<dasharray>
为一个逗号或空格分隔的数值列表。表示各个虚线端的长度。可以是固定的长度值,也可以是百分比值;inherit
表继承。stroke-dashoffset
表示虚线的起始偏移。可选值为:<percentage>
,<length>
,inherit
. 百分比值,长度值,继承。stroke-opacity
表示描边透明度。默认是1
先创建一个AVG画布
定义样式:
<style>
.svgStyle{
border: solid 1px #000000;
margin: 0 auto;
display: block
}
.pathStyle{
stroke:#000000;
stroke-width:2px;
fill:none;
stroke-dasharray:0px;
stroke-linecap:round;
stroke-dashoffset:0;
}
</style>
创建SVG:并随意画个图形
<svg width="1200px" height="600px" version="1.1" xmlns="http://www.w3.org/2000/svg" class="svgStyle">
<path d="M 0 300 Q 200 500 400 300 Q 600 500 800 300" class="pathStyle" />
</svg>
-------------------------------------------------------------------------------------------------------------------------------
通过改变stroke-dasharray和stroke-dashoffset两个属性我们可以发现动画的实现原理是
首先把stroke-dasharray的值设成超过线条长度的值,这时候线是看不到,只显示空白部分,然后通过strke-dashoffset的偏移属性让线条逐渐显示出来。
改变strke-dashoffset的属性实现动画,可以用CSS也可以用JS方法
css方法:
.pathStyle{
stroke:#000000;
stroke-width:2px;
fill:none;
stroke-dasharray:500;
stroke-linecap:round;
stroke-dashoffset:0;
animation: dash 5s linear linear infinite;
-webkit-animation:dash 5s infinite linear both;
}
@-webkit-keyframes dash {
from{
stroke-dashoffset: 1000;
}
to {
stroke-dashoffset: 0;
}
}
@keyframes dash {
from{
stroke-dashoffset: 1000;
}
to {
stroke-dashoffset: 0;
}
}
var path=document.querySelector('.pathStyle');
var length=path.getTotalLength();
var init=1000;
setInterval(function(){
--init;
if(init<0){
init=1000
}
path.style.strokeDashoffset=init
},10)
</script>
- svg线条动画基础
- SVG基础七:线条
- SVG+CSS3 简单线条动画
- 简单的SVG线条动画
- SVG技术入门:线条动画实现原理
- SVG技术入门:线条动画实现原理
- HTML5 SVG图形轮廓线条绘制动画插件-vivus
- HTML5 SVG简单的动态绘制轮廓线条动画插件
- html5+d3 svg 线条、图形颜色渐变动画
- SVG 形状_线条
- svg基础 6 动画和交互性
- Android动画 SVG VectorDrawable 基础三
- Android动画 SVG VectorDrawable 基础一
- Android动画 SVG VectorDrawable 基础二
- Android动画 SVG VectorDrawable 基础四
- svg 与svg动画
- Android动画 SVG VectorDrawable 基础五 Path动画
- svg动画
- 区块链的未来潜力
- jsp 取 map<String,List>值
- Android 判断imageview角度并旋转
- windows下 在cmd 中 后台运行程序 关闭程序
- 系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式
- svg线条动画基础
- 如何在Scope的query界面中创建按钮并捕获按钮事件
- laravel 学习笔记——路由(基础)
- mysql 视图权限-设置用户其它ip可用
- ubuntu 14 系统的网络服务与此版本的网络管理器不兼容
- Android Intent最全面的解析
- CUICatalog: Invalid asset name supplied: (null)
- lucene(四) lucene分词器
- 【Java提高】Java中是如何实现克隆