使用 CSS 对 background-position 属性执行动画

cssweb developmentfront end technology更新于 2024/9/18 22:04:17

使用 @keyframes 为背景位置添加动画。要使用 CSS 对 background-position 属性执行动画,您可以尝试运行以下代码

示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 500px;
            height: 400px;
            background: yellow;
            background-image: url('https://www.cainiaomax.com/latest/microservice_architecture.png');
            animation: myanim 3s infinite;
            background-position: bottom left;
         }
         @keyframes myanim {
            20% {
               background-color: maroon;
               background-position: bottom right;
            }
         }
      </style>
   </head>
   <body>
      <div></div>
   </body>
</html>

相关文章


有用资源