其他分享
首页 > 其他分享> > CSS动画效果-奔跑的熊

CSS动画效果-奔跑的熊

作者:互联网

<!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>奔跑的熊熊</title>
    <style>
      body {
        background-color: #ccc;
      }
      div {
        position: absolute;
        top: 500px;
        width: 200px;
        height: 100px;
        background: url(../images/bear.png) no-repeat;
        /* 2.调用动画 */
        /* 运动速度曲线默认为ease,这里用steps(8)步长,分8步完成 */
        /* 我们元素可以添加多个动画,用逗号分隔 */
        animation: bear 1s steps(8) infinite, move 3s forwards;
      }
      /* 1.设置动画 */
      @keyframes bear {
        0% {
          background-position: 0 0;
        }
        100% {
          /* 从左往右走 */
          background-position: -1600px 0;
        }
      }
      @keyframes move {
        0% {
          left: 0;
        }
        100% {
          left: 50%;
          /* 中间位置 margin-left:-100px; 等价于transform: translate(-50%); */
          transform: translateX(-50%);
        }
      }
    </style>
  </head>
  <body>
    <div></div>
  </body>
</html>

标签:动画,50%,bear,奔跑,background,position,CSS,left
来源: https://blog.csdn.net/nuomi_w/article/details/121452971