画线动画——SVG版和纯CSS版
概述
我们常常在网站中看到一些画线的动画效果,非常炫酷,大多数这种画线动画效果是通过SVG实现的,也有不少是用纯css实现的,下面我总结了一下这2种方法,供以后开发时参考,相信对其他人也有用。
SVG实现画线效果
在svg里面,可以用stroke-dashoffset属性来实现画线效果,示例如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>svg</title>
<style>
path{
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
animation: draw 5s ease 3;
}
@keyframes draw{
0%{
stroke-dashoffset: 1000;
}
100%{
stroke-dashoffset: 0;
}
}
</style>
</head>
<body>
<svg width="400px" height="400px" viewBox="100 250 400 400" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="M153 334
C153 334 151 334 151 334
C151 339 153 344 156 344
C164 344 171 339 171 334
C171 322 164 314 156 314
C142 314 131 322 131 334
C131 350 142 364 156 364
C175 364 191 350 191 334
C191 311 175 294 156 294
C131 294 111 311 111 334
C111 361 131 384 156 384
C186 384 211 361 211 334
C211 300 186 274 156 274"
style="fill:white;stroke:red;stroke-width:2"/>
</svg>
</body>
</html>
需要注意的是,必须要设置stroke-dasharray属性,并且和stroke-dashoffset一样长;其中1000是个自定义的值,只要比画线的总长度长就行了。
纯css画线
对于长方形或者正方形这些规则的图形,用css的transition效果即可,代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>svg</title>
<style>
#border {
position: relative;
width: 300px;
height: 300px;
}
.border-top {
position: absolute;
top: 50px;
left: 50px;
width: 0;
height: 8px;
background-color: #333;
transition: all .5s 1s;
}
.border-bottom {
position: absolute;
bottom: 50px;
right: 50px;
width: 0;
height: 8px;
background-color: #333;
transition: all .5s 2s;
}
.border-right {
position: absolute;
top: 50px;
left: 250px;
width: 8px;
height: 0;
background-color: #333;
transition: all .5s 1.5s;
}
.border-left {
position: absolute;
bottom: 50px;
left: 50px;
width: 8px;
height: 0;
background-color: #333;
transition: all .5s 2.5s;
}
.animate .border-top, .animate .border-bottom {
width: 200px;
}
.animate .border-right, .animate .border-left {
height: 200px;
}
</style>
</head>
<body>
<div id="border">
<i class="border-top"></i>
<i class="border-right"></i>
<i class="border-bottom"></i>
<i class="border-left"></i>
</div>
<script>
setTimeout(function() {
document.getElementById('border').className += ' animate';
}, 500);
</script>
</body>
</html>
画线动画——SVG版和纯CSS版的更多相关文章
- WPF 画线动画效果实现
原文:WPF 画线动画效果实现 弄了将近三天才搞定的,真是艰辛的实现. 看了很多博客,都太高深了,而且想要实现的功能都太强大了,结果基础部分一直实现不了,郁闷啊~ 千辛万苦终于找到了一个Demo,打开 ...
- HTML自定义radio单选按钮(纯css版,样式可以随意改变)
html: <div> <input id="item1" type="radio" name="item" value= ...
- 纯CSS制作加<div>制作动画版哆啦A梦
纯CSS代码加上<div>制作动画版哆啦A梦(机器猫) 哆啦A梦(机器猫)我们大家一定都很熟悉,今天给大家演示怎么用纯CSS代码,来做一个动画版的哆啦A梦. 效果图: ###下面代码同学可 ...
- 纯CSS实现帅气的SVG路径描边动画效果(转载)
本文转载自: 纯CSS实现帅气的SVG路径描边动画效果
- 纯JS画点、画线、画圆的方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 用纯css画个三角形
用纯css画个三角形以下是源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- [stm32] 利用uc-gui封装画图和画线函数移植51上的模拟动画
>_<:这里的动画是黄色矩形区域中一个模仿俯视图的起重机运作动画,一个是模仿主视图的吊钩的运动.通过改变初始Init函数中的数据b_x,b_y实现矩形区域的移动.当实时采集时要首先根据起重 ...
- 纯css做的安卓开机动画
随着css3的发展,越来越多的负责绚丽的效果可以由纯css来完成了.用css3实现的动画效果丝毫不必js实现的逊色,而且浏览器对css渲染的速度远比js快,大多数时候css的体积也不js小.其中css ...
- 一个纯CSS DIV天气动画图标【转扒的】
<p> </p> <style><!-- /* SUNNY */ .sunny { -webkit-animation: sunny 15s linear i ...
随机推荐
- 安装mitmproxy
https://www.jianshu.com/p/1dd40826113b 先连接到同一个局域网,再访问官网下载描述文件
- 简单的StringBuffer实现
package com.letv.test.base; import java.util.Arrays; public class StringBuffer { private char[] valu ...
- 自学elastic search
工作也有一段时间了,虽然来这个公司之后学会了几门不同的语言,但想拨尖还是任重道远. 想往高级程序员甚至是架构师方向发展.他仍然是我的学习对象.我现在做着的,无非是他玩剩下的罢了. luncene之前有 ...
- java上传文件常见几种方式
1.ServletFileUpload 表单提交中当提交数据类型是multipare/form-data类型的时候,如果我们用servlet去做处理的话,该http请求就会被servlet容器,包装成 ...
- 解决Ubuntu 16.04 上Android Studio2.3上面运行APP时提示DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs的问题
本人工作环境:Ubuntu 16.04 LTS + Android Studio 2.3 AVD启动之后,运行APP,报错提示: DELETE_FAILED_INTERNAL_ERROR Error ...
- MySQL语法大全_自己整理的学习笔记(MySQL语句 整理二)
select * from emp; #注释 #--------------------------- #----命令行连接MySql--------- #启动mysql服务器 net start m ...
- 不能ping通主机名
https://www.linuxidc.com/Linux/2017-03/142253.htm sudo apt-get install winbind , sudo apt-get instal ...
- js unicode转中文 方案概述联网LED照明方案可执行全部的DALI 和
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#中get和set属性的作用
c#在定义类时,通常要把类中声明的对象封装起来,使得外界不能访问这个属性.上述代码中如果去掉set部分,则外界只能读取name的值,如果去掉get部分,则只能给name赋值.这样就可以控制外界对私有属 ...
- 制作DNS字典
1.收集字典 一般kali自带的DNS爆破工具都会有自己的字典,使用 dpkg -L dns爆破软件名 查询字典的路径.txt文件一般是字典. 合并到一个txt文件中. 2.删除字典中重复的字符串 ...