先看效果:
clip-path描好效果会更好~
原理:
就是两段文本重叠一起,底层的没颜色,上面层的有颜色,然后通过动画再通过clip-path属性截取上层的部分显示~
实现:
1.定义两个相同的文本:
<body>
<h1 class="diyi">Ice~Land</h1>
<h1 class="dier">Ice~Land</h1>
</body>
2.给他们样式:
h1{
position: absolute;
font-size: 5em;
}
3.设置底层文本样式:
.diyi{
-webkit-text-stroke:rgba(79, 79, 224,.7) 2px;
color: transparent;
}
-webkit-text-stroke…:描边宽度和描边颜色;
color: transparent; 文本透明;
4.设置上层文本样式:
.dier{
color: rgba(29, 29, 236, 1);
animation: move 3s ease-in-out infinite;
}
ease-in-out :动画以低速开始和结束
5.通过clip-path裁剪只显示部分区域,不同时间裁剪不同内容就形成动态效果:
@keyframes move{
0%{
clip-path: polygon(0% 62%, 14% 55%, 24% 51%, 32% 51%, 41% 56%, 50% 59%, 60% 59%, 69% 55%, 76% 49%, 84% 48%, 93% 50%, 100% 54%, 100% 100%, 0 100%);
}
50%{
clip-path: polygon(0% 62%, 10% 62%, 23% 68%, 36% 68%, 44% 64%, 50% 59%, 59% 54%, 67% 55%, 74% 59%, 86% 62%, 94% 61%, 100% 54%, 100% 100%, 0 100%);
}
100%{
clip-path: polygon(0% 62%, 14% 55%, 24% 51%, 32% 51%, 41% 56%, 50% 59%, 60% 59%, 69% 55%, 76% 49%, 84% 48%, 93% 50%, 100% 54%, 100% 100%, 0 100%);
}
}
6.第五步可以去一个网站动态生成想要描绘clip-path:
这里:https://www.html.cn/tool/css-clip-path/
在这个网站,直接点击裁成什么样,就自动生成代码,很方便~
完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(12, 12, 12);
}
h1{
position: absolute;
font-size: 5em;
}
.diyi{
-webkit-text-stroke:rgba(79, 79, 224,.7) 2px;
color: transparent;
}
.dier{
color: rgba(29, 29, 236, 1);
animation: move 3s ease-in-out infinite;
}
@keyframes move{
0%{
clip-path: polygon(0% 62%, 14% 55%, 24% 51%, 32% 51%, 41% 56%, 50% 59%, 60% 59%, 69% 55%, 76% 49%, 84% 48%, 93% 50%, 100% 54%, 100% 100%, 0 100%);
}
50%{
clip-path: polygon(0% 62%, 10% 62%, 23% 68%, 36% 68%, 44% 64%, 50% 59%, 59% 54%, 67% 55%, 74% 59%, 86% 62%, 94% 61%, 100% 54%, 100% 100%, 0 100%);
}
100%{
clip-path: polygon(0% 62%, 14% 55%, 24% 51%, 32% 51%, 41% 56%, 50% 59%, 60% 59%, 69% 55%, 76% 49%, 84% 48%, 93% 50%, 100% 54%, 100% 100%, 0 100%);
}
}
</style>
<body>
<h1 class="diyi">Ice~Land</h1>
<h1 class="dier">Ice~Land</h1>
</body>
</html>
总结
哈哈~
更多:
炫彩流光按钮
…