网站专题建设seo推广排名平台有哪些
上大学的玩 ae 的时候,就曾遇到过这个特效。偶然在百度看到了类似特效,没想到竟然能用 css 实现,所以就研究了一下,文字扫光效果如下:
实现思路:
- 光效移动效果,可以通过 background-image 设置渐变色模拟光效,然后用动画移动背景图片去移动光效
- 光效掠过文字时,文字颜色需要和光效颜色一致,这里需要使用 css3 的 background-clip:text 属性,同时将前景色设置为透明,这样在背景移动的时候,文字颜色就会和背景色保持一致
代码如下:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>扫光文字</title><style>.shine-box {width: 500px;height: 100px;margin: auto;padding-top: 60px;border-radius: 10px;text-align: center;background-color: black;font-weight: bolder;}.shine-span {background: #656565 linear-gradient(to left, transparent, #fff, transparent) no-repeat 0 0;background-size: 20% 100%;background-position: 0 0;background-clip: text;-webkit-background-clip: text;color: transparent;animation: shine 2s infinite;}@keyframes shine {from {background-position: 0% 0%;}to {background-position: 100% 100%;}}</style>
</head>
<body><div class="shine-box"><span class="shine-span">玉不啄,不成器;人不学,不知道</span></div>
</body>
</html>
注意:background-clip 在 chrome 中需要添加厂商前缀 -webkit- 才能好使