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>