锥形旋转渐变——Houdini API 的初步谈搜

133 阅读1分钟

使用conic-gradient完成锥形渐变,developer.mozilla.org/zh-CN/docs/…

使用@property定义CSS属性,使之可以被animation所响应

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta
    name="viewport"
    content="width=device-width, initial-scale=1.0"
  >
  <title>Document</title>
  <link
    rel="stylesheet"
    href="./index.css"
  >
</head>

<body>
  <div class="wrapper">
    <div class="inner"></div>
  </div>
</body>

</html>
html,
body {
  margin: 0;
}

body {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

.wrapper {
  --angle: 0deg;
  background-color: white;
  padding: 5px;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background-image: conic-gradient(
    from var(--angle),
    #ff0000,
    #ff7f00,
    #ffff00,
    #00ff00,
    #0000ff,
    #4b0082,
    #8b00ff,
    #ff0000
  );
  animation: spin 3s linear infinite;
}

@keyframes spin {
  from {
    --angle: 0deg;
  }
  to {
    --angle: 360deg;
  }
}

.inner {
  width: 100%;
  height: 100%;
  background-color: white;
  border-radius: 50%;
}