如何做文字光斑效果,如图:
具体实现代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
html,body{
height: 100%;
overflow: hidden;
background: black;
text-align: center;
}
h1{
margin-top: 50px;
display: inline-block;
font: bold 80px "微软雅黑";
color: rgba(255,255,255,0.3);
background: linear-gradient(120deg,rgba(255,255,255,0) 100px,rgba(255,255,255,1) 180px,rgba(255,255,255,0) 260px);
background-repeat: no-repeat;
-webkit-background-clip: text;
}
</style>
<body>
<h1>atguigu尚硅谷</h1>
<script>
var h1 = document.querySelector("h1");
var flag = -160;
setInterval(function(){
flag+=10;
if(flag==900){
flag=-160;
}
h1.style.backgroundPosition = flag+"px";
},30)
</script>
</body>
</html>
网友评论