当前位置: 首页> 财经> 产业 > 前端 CSS 经典:边框转圈动画效果

前端 CSS 经典:边框转圈动画效果

时间:2025/7/9 15:46:32来源:https://blog.csdn.net/weixin_64684095/article/details/139815901 浏览次数:0次

前言:首先我们要知道 css 动画只对数值类的 CSS 属性起作用。要实现边框转圈动画效果,实际就是渐变背景的旋转。但是在以前,渐变背景是不支持动画的。现在我们可以利用浏览器新出的 Houdini API 来实现这个动画效果。Houdini API 特别强大,允许开发者干扰浏览器渲染过程。其中有一个属性@property 允许开发者在样式代码里面,自己定义样式属性。

效果图:

代码实现: 

<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><metaname="viewport"content="initial-scale=1.0, user-scalable=no, width=device-width"/><title>document</title><style>body {background: #000;}.card::before {z-index: -1;filter: blur(20px);}.card::after {content: "";position: absolute;inset: 8px;background: #191c29;border-radius: inherit;}@property --direc {syntax: "<angle>";initial-value: 0deg;inherits: false;}.card {position: relative;width: 200px;height: 400px;margin: 100px auto;--direc: 0deg;color: red;background-image: linear-gradient(var(--direc),#5ddcff,#3c67e3,43%,#4e00c2);animation: rotate 3s linear infinite;}@keyframes rotate {to {--direc: 360deg;}}</style></head><body><div class="card"></div><script></script></body>
</html>

关键字:前端 CSS 经典:边框转圈动画效果

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: