image.png

    核心思路:body加冰山背景图片,定义动画0到-1600px的移动,30s的动画时长,实现背景移动;div加小熊背景图片,定义动画0到-1600px的移动实现小熊奔跑,再定义动画小熊跑body的50%的x轴。

    1. <style>
    2. body {
    3. background: url(media/bg1.png) no-repeat;
    4. animation: bg 20s 2.9s linear;
    5. }
    6. @keyframes bg {
    7. 0% {
    8. background-position: 0 0;
    9. }
    10. 100% {
    11. background-position: -1600px 0;
    12. }
    13. }
    14. @keyframes go {
    15. 0% {
    16. background-position: 0 0;
    17. }
    18. 100% {
    19. background-position: -1600px 0;
    20. }
    21. }
    22. @keyframes stop {
    23. 0% {
    24. left: 0;
    25. }
    26. 100% {
    27. position: absolute;
    28. left: 50%;
    29. margin-left: -100px;
    30. }
    31. }
    32. div {
    33. position: relative;
    34. transform: translateY(237px);
    35. width: 200px;
    36. height: 100px;
    37. background: url(media/bear.png) no-repeat;
    38. animation: go 0.5s steps(8) infinite, stop 3s linear forwards;
    39. }
    40. </style>
    41. </head>
    42. <body>
    43. <div></div>
    44. </body>