使用 CSS 對 background-position 屬性執行動畫


使用 @keyframes 對背景位置進行動畫處理。要使用 CSS 在 background-position 屬性上實現動畫,你可以嘗試執行以下程式碼 :

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 500px;
            height: 400px;
            background: yellow;
            background-image: url('https://tutorialspoint.tw/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>

更新於:2020 年 6 月 25 日

332 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.