/
gradientBorderAnimation3(使用clip-path).html
62 lines (61 loc) · 1.46 KB
/
gradientBorderAnimation3(使用clip-path).html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body,
html {
width: 100%;
height: 100%;
display: flex;
}
div {
position: relative;
margin: auto;
width: 160px;
line-height: 160px;
text-align: center;
font-size: 24px;
}
div::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 2px solid gold;
transition: all 0.5s;
-webkit-animation: clippath 3s infinite linear;
animation: clippath 3s infinite linear;
}
@keyframes clippath {
0%,
100% {
-webkit-clip-path: inset(0 0 95% 0);
clip-path: inset(0 0 95% 0);
}
25% {
-webkit-clip-path: inset(0 95% 0 0);
clip-path: inset(0 95% 0 0);
}
50% {
-webkit-clip-path: inset(95% 0 0 0);
clip-path: inset(95% 0 0 0);
}
75% {
-webkit-clip-path: inset(0 0 0 95%);
clip-path: inset(0 0 0 95%);
}
}
</style>
<!-- 用 clip-path
的优点是,切割出来的边框不会产生小三角。同时,这种方法,也是支持圆角
border-radius 的 -->
</head>
<body>
<div>Hello</div>
</body>
</html>