钟摆案例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <style>
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. }
  13. .box{
  14. width:150px;
  15. height:400px;
  16. background: url("clock.png") no-repeat;
  17. margin: auto;
  18. /* animation : 动画的名字 时间 匀速 无限 */
  19. animation:move 2s linear infinite;
  20. transform-origin: top center;
  21. }
  22. /* @keyframes: 自定义动画 */
  23. @keyframes move{
  24. 0%{
  25. transform: rotate(0deg);
  26. }
  27. 25%{
  28. transform: rotate(45deg);
  29. }
  30. 50%{
  31. transform: rotate(0deg);
  32. }
  33. 75%{
  34. transform: rotate(-45deg);
  35. }
  36. 100%{
  37. transform: rotate(0deg);
  38. }
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="box"></div>
  44. </body>
  45. </html>

clock.png

3D魔方案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            background: yellow;
        }
        .box{
            width: 320px;
            height: 560px;
            margin: 100px auto;
            background: url('./img/zf_cubeBg.jpg') no-repeat 100% 100%;
            /* 视距 */
            perspective: 3000px;
        }
        .list{
            position: relative;
            transform-style: preserve-3d;
            width: 100%;
            height: 100%;
            list-style: none;
            animation: move 6s infinite;
            transform:  rotateY(90deg);
        }
        @keyframes move {
            0%{
                transform: translate(200px) rotateX(90deg);
            }
            50%{
                transform: translate(100px) rotateY(180deg);
            }
            100%{
                transform: translateY(100px) rotateZ(45deg);
            }
        }
        .list li{
            width: 200px;
            height: 200px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-top: -100px;
            margin-left: -100px;
        }
        .list li:nth-child(1){
            transform: translateZ(100px);
        }
        .list li:nth-child(2){
            transform: translateZ(-100px) rotateY(180deg);
        }
        .list li:nth-child(3){
            transform: translateY(100px) rotateX(-90deg);
        }
        .list li:nth-child(4){
            transform: translateY(-100px) rotateX(90deg);
        }
         /* 从正轴向负轴看,逆时针负,顺时针为正;*/
        .list li:nth-child(5){
            transform: translateX(100px) rotateY(90deg);
        }
        .list li:nth-child(6){
            transform: translateX(-100px) rotateY(-90deg);
        }
        .list li img{
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="box">
        <ul class="list">
            <li><img src="./img/zf_cube1.png" alt=""></li>
            <li><img src="./img/zf_cube2.png" alt=""></li>
            <li><img src="./img/zf_cube3.png" alt=""></li>
            <li><img src="./img/zf_cube4.png" alt=""></li>
            <li><img src="./img/zf_cube5.png" alt=""></li>
            <li><img src="./img/zf_cube6.png" alt=""></li>
        </ul>
    </div>
</body>
</html>