Fei Blog

N边形过渡动画

2018/09/25
阅读量:

整理一波CSS的笔记。

N变形过渡动画实现,clip-path

本篇是随机生成2000个点,clip-path连接这些点,进行随机变换。
代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<div></div>
<style lang='scss'>
div {
width: 300px;
height: 300px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: all .5s;
transition-timing-function: cubic-bezier(.92,-0.5,1,.12);
border-radius: 50%;
}
</style>
<script type="text/javascript">
setInterval(function() {
const length = 2000;
let el = document.querySelectorAll("div")[0];
let coordinate = "";
for (let i = 0; i < length; i++) {
coordinate +=
parseInt(Math.random() * 10000) / 100 +
"% " +
parseInt(Math.random() * 10000) / 100 +
"%, ";
}
coordinate = "polygon(" + coordinate.slice(0, -2) + ")";
el.style.clipPath = coordinate;
el.style.backgroundColor =
"#" + (~~(Math.random() * (1 << 24))).toString(16);
}, 500);
</script>

参考链接

CATALOG
  1. 1. N变形过渡动画实现,clip-path
  2. 2. 参考链接