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>
相关推荐
Kurisu5752 天前
探灵直播2026最新官方正版免费下载 一键转存 永久更新 (看到速转存 资源随时走丢)
游戏·游戏引擎·游戏程序·动画·关卡设计
暗冰ཏོ3 天前
《前端动画超详细教程:CSS、JS 动画原理、实战与性能优化》
前端·javascript·css·动画
司南-70498 天前
如何下载无损 bilbili视频?
运维·服务器·动画·技术美术
2601_956002819 天前
冬日狂想曲(赠去马赛克补丁)2026.5.13最新版免费下载 转存后自动更新 (看到请立即转存 资源随时失效)pc手机版通用
智能手机·游戏引擎·电脑·游戏程序·动画·游戏美术
2601_956002819 天前
侠盗猎车手罪恶都市GTA3 2026.5.13最新中文汉化版免费下载 转存后自动更新 (看到请立即转存 资源随时失效)pc手机通用
游戏·游戏程序·动画·游戏策划·游戏美术·gta
儿歌八万首23 天前
Jetpack Compose Canvas 进阶:结合 animateFloatAsState 让自定义图形动起来
android·动画·compose
高心星1 个月前
鸿蒙6.0应用开发——一镜到底动画实践案例
动画·鸿蒙6.0·harmonyos6.0·转场动画·一镜到底动画
不喝水就会渴1 个月前
从基础到实战:鸿蒙 ArkUI 属性动画开发指南
华为·交互·动画·harmonyos
高心星1 个月前
鸿蒙6.0应用开发——基础动画实践案例
华为·动画·鸿蒙6.0·harmonyos6.0·水波动画·微动画·手势动画
GISer_Jing1 个月前
前端图片、动图与动画全解析(含PNG/APNG/Lottie/GIF/Canvas/WebGL/WebGPU)
前端·3d·动画·webgl