动画.gif

    1. <div class="clock">
    2. <div class="dial"></div>
    3. <div class="pendulum"></div>
    4. </div>
    1. * {
    2. box-sizing: border-box;
    3. margin: 0;
    4. padding: 0;
    5. }
    6. body {
    7. height: 100vh;
    8. background: lightblue;
    9. }
    10. .dial {
    11. width: 100px;
    12. height: 100px;
    13. margin: 0 auto;
    14. background: pink;
    15. border-radius: 50%;
    16. border: 8px solid #fff;
    17. }
    18. .pendulum {
    19. width: 10px;
    20. height: 150px;
    21. background: #fff;
    22. margin: 0 auto;
    23. position: relative;
    24. top: -4px;
    25. transform-origin: center top;
    26. animation: swing 2s infinite linear;
    27. }
    28. .pendulum::before {
    29. content: '';
    30. display: box;
    31. width: 30px;
    32. height: 30px;
    33. background: pink;
    34. border-radius: 50%;
    35. position: absolute;
    36. bottom: 0;
    37. left: 50%;
    38. transform: translate(-50%, 50%);
    39. border: 4px solid #fff;
    40. }
    41. @keyframes swing {
    42. 0% {
    43. transform: rotate(45deg)
    44. }
    45. 25% {
    46. transform: rotate(0)
    47. }
    48. 50% {
    49. transform: rotate(-45deg)
    50. }
    51. 75% {
    52. transform: rotate(0)
    53. }
    54. 100% {
    55. transform: rotate(45deg)
    56. }
    57. }