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>
相关推荐
xiangxiongfly9154 天前
Android 共享元素转场效果
android·动画·共享元素转场效果
儿歌八万首1 个月前
Jetpack Compose 动画实战:让你的 UI 动起来
android·kotlin·动画·compose
weixin_465790911 个月前
混合储能系统容量优化:基于粒子群算法的Matlab实现
动画
2401_841495641 个月前
【Python高级编程】2026 丙午马年元旦祝福程序
python·动画·tkinter·程序·pyinstaller·元旦·turtle
编码旅者1 个月前
《Virt A Mate(VAM)》免安装豪华版v1.22中文汉化整合
游戏引擎·图形渲染·vr·动画
FVV11231 个月前
电脑录屏工具Bandicam 无时长限制,支持4K画质
eclipse·游戏引擎·ar·动画·ogre
星海浮沉1 个月前
一文了解 Flutter 动画
flutter·动画
Poetinthedusk1 个月前
WPF动画制作分享
wpf·动画
╰つ栺尖篴夢ゞ2 个月前
HarmonyOS Next之深入解析使用Grid实现瀑布流网格布局
动画·harmonyos next·grid·瀑布流布局
hey202005282 个月前
如何将 Maya 首选项重置为默认值
动画·maya