HTML5+CSS3实现炫彩的聚光灯文字效果,手电筒照过去的赶脚,是不是挺有意思的,赶紧收藏起来学起来,说不定日后工作中某一些特定场景会用得上。
效果:
源码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>好玩的聚光灯效果</title>
<link rel="stylesheet" href="../css/15.css">
</head>
<body>
<h1>helloworld</h1>
</body>
</html>
*{
/* 初始化 取消页面元素内外边距 */
margin: 0;
padding: 0;
}
body{
background-color: #222;
/* 弹性布局 水平、垂直居中 */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
/* background: linear-gradient(200deg,#485563,#29323c); */
}
h1{
color: #333;
text-transform: uppercase;
font-size: 112px;
position: relative;
}
h1::after{
content: "helloworld";
color: transparent;
position: absolute;
top: 0;
left: 0;
background: linear-gradient(to right,#FF69B3,#FE0000,#FFA401,#FFFF01,#008102,#40E1D2,#410098,#9400D4);
/* 以文字的范围来裁剪背景图片 */
background-clip: text;
-webkit-background-clip: text;
/* 将元素裁剪为一个圆形(100px表示圆的直径,0% 50%表示圆心位置) */
clip-path: circle(100px at 0% 50%);
animation: light 5s infinite;
}
/* 定义动画 改变圆心的位置 */
@keyframes light{
0%{
clip-path: circle(100px at 0% 50%);
}
50%{
clip-path: circle(100px at 100% 50%);
}
100%{
clip-path: circle(100px at 0% 50%);
}
}