当前位置:   article > 正文

前端知识案例学习15-实现3d得旋转_前端3维环形旋转效果 切图

前端3维环形旋转效果 切图

index.html

  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. <link rel="stylesheet" href="style.css" />
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <main>
  12. <div class="cube">
  13. <div class="img1"></div>
  14. <div class="img2"></div>
  15. <div class="img3"></div>
  16. <div class="img4"></div>
  17. <div class="img5"></div>
  18. <div class="img6"></div>
  19. </div>
  20. </main>
  21. </body>
  22. </html>

css

  1. html,
  2. body {
  3. margin: 0;
  4. }
  5. * {
  6. box-sizing: border-box;
  7. }
  8. body {
  9. background-color: #2f3542;
  10. }
  11. main {
  12. display: flex;
  13. align-items: center;
  14. justify-content: center;
  15. height: 100vh;
  16. }
  17. .cube {
  18. width: 250px;
  19. height: 250px;
  20. transform-style: preserve-3d;
  21. transform-origin: 125px 125px 0;
  22. animation: rotate-cube 10s ease-in-out infinite;
  23. }
  24. .cube > div {
  25. width: 250px;
  26. height: 250px;
  27. background-size: cover;
  28. background-position: center center;
  29. opacity: 0.8;
  30. position: absolute;
  31. box-shadow: inset 0 0 4px 2px rgba(106, 106, 106, 0.4);
  32. }
  33. /* 前 */
  34. .cube .img1 {
  35. background-image: url("https://images.pexels.com/photos/274131/pexels-photo-274131.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  36. transform: rotateY(0deg) translateZ(125px);
  37. }
  38. /* 右 */
  39. .cube .img2 {
  40. background-image: url("https://images.pexels.com/photos/1480690/pexels-photo-1480690.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  41. transform: rotateY(90deg) translateZ(125px);
  42. }
  43. /* 左 */
  44. .cube .img3 {
  45. background-image: url("https://images.pexels.com/photos/36487/above-adventure-aerial-air.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  46. transform: rotateY(-90deg) translateZ(125px);
  47. }
  48. /* 下 */
  49. .cube .img4 {
  50. background-image: url("https://images.pexels.com/photos/338713/pexels-photo-338713.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  51. transform: rotateX(90deg) translateZ(125px);
  52. }
  53. /* 上 */
  54. .cube .img5 {
  55. background-image: url("https://images.pexels.com/photos/325044/pexels-photo-325044.jpeg?cs=srgb&dl=close-up-of-fish-over-black-background-325044.jpg&fm=jpg");
  56. transform: rotateX(-90deg) translateZ(125px);
  57. }
  58. /* 后 */
  59. .cube .img6 {
  60. background-image: url("https://images.pexels.com/photos/404280/pexels-photo-404280.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  61. transform: rotateY(180deg) translateZ(125px);
  62. }
  63. @keyframes rotate-cube {
  64. 0% {
  65. transform: rotateX(0deg) rotateY(0deg);
  66. }
  67. 20% {
  68. /* 右边图片 */
  69. transform: rotateY(-90deg);
  70. }
  71. 40% {
  72. /* 上 */
  73. transform: rotateX(-90deg);
  74. }
  75. 60% {
  76. /* 左 */
  77. transform: rotateY(90deg);
  78. }
  79. 80% {
  80. /* 下 */
  81. transform: rotateX(90deg);
  82. }
  83. 100% {
  84. transform: rotateX(0deg) rotateY(0deg);
  85. }
  86. }

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号