background-image: linear-gradient 属性hover动画

1.效果

2.代码

复制代码
<!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>svg文字动画</title>
  <link rel="stylesheet" href="test.css">
  <style>
    @property --property-color1 {
      syntax: "<color>";
      inherits: false;
      initial-value: yellow;
    }
    @property --property-color2 {
      syntax: "<color>";
      inherits: false;
      initial-value: green;
    }
    :root {
      --a:red;
    }
    #box {
      width: 800px;
      height: 300px;
      margin: 200px auto;
      cursor: pointer;
      color: var(--a);
      background-image: linear-gradient(60deg, var(--property-color1),  var(--property-color2));
      transition: --property-color1 .5s ease-out,--property-color2 .5s ease-out;
    }
    #box:hover {
      --property-color1: green;
      --property-color2: yellow;
    }

    #box2 {
      width: 800px;
      height: 300px;
      margin: 0 auto;
      cursor: pointer;
      background-image: linear-gradient(60deg, yellow,green,green,yellow);
      background-size: 200% 100%;
      background-position: 0% 0%;
      transition: all .4s ease-out;
    }
    #box2:hover {
      background-position: 100% 0%;
    }
  </style>
</head>

<body>
  <div id="app">
    <div id="box">box</div>
    <div id="box2">box2</div>
    <div id="demoCanvas"></div>

    <script>

    </script>
  </div>
</body>

</html>
相关推荐
Hh6910241 天前
2026年10月合肥多动症排名
动画
Quz3 天前
QML TabBar 标签栏交互效果合集
qt·动画·qml
CappuccinoRose7 天前
CSS 动效基础
前端·css·动画·animation·transition
hey202005288 天前
Maya怎么云渲染?云渲染使用教程详解!
3dsmax·动画·maya·3d渲染
Quz9 天前
QML PathView:直线路径与曲线路径
qt·动画·qml
传奇开心果编程10 天前
【React Native娓娓道来】第9课 动画与手势:Animated、Reanimated 与 Pressable 进阶
移动开发·动画·手势·编程语言理论·开发范式·编程框架·声明式ui
2601_9613681511 天前
福州看诊多动症注意力不集中治疗效果好
动画
zwd200511 天前
Manim add_sound 用法详解:time_offset、gain、多条音频与旁白对齐(2026 最新教程,0.21.0)
python·音频·动画·manim·数学动画·add_sound
传人once13 天前
悬停旋转放大和位移效果如何写
javascript·css·动画