当前位置:Gxlcms > css > 如何使用css3实现魔方的动画效果(完整代码)

如何使用css3实现魔方的动画效果(完整代码)

时间:2021-07-01 10:21:17 帮助过:21人阅读

本篇文章给大家带来的内容是关于如何使用css3实现魔方的动画效果(完整代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

  1. <!DOCTYPE html>
  2. <html>
  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: 300px;
  15. height: 300px;
  16. margin: 100px auto;
  17. position: relative;
  18. transform-style: preserve-3d;
  19. transform: rotateX(-30deg) rotateY(30deg);
  20. animation: updown 3s linear 3s infinite alternate;
  21. }
  22. @keyframes updown{
  23. 0%{
  24. transform: rotateX(-30deg) rotateY(30deg);
  25. }
  26. 100%{
  27. transform: rotateX(360deg) rotateY(360deg);
  28. }
  29. }
  30. ul{
  31. list-style: none;
  32. }
  33. .box li{
  34. width: 100px;
  35. height: 100px;
  36. border: 2px solid #fff;
  37. box-sizing: border-box;
  38. float: left;
  39. position: relative;
  40. }
  41. .box>div{
  42. position: absolute;
  43. width: 100%;
  44. height: 100%;
  45. opacity: 0.5
  46. }
  47. .box .front{
  48. /*background-color: deeppink;*/
  49. transform: translateZ(150px);
  50. }
  51. .box .behind{
  52. /*background-color: yellow;*/
  53. transform: translateZ(-150px);
  54. }
  55. .box .left{
  56. /*background-color: greenyellow;*/
  57. transform: rotateY(-90deg) translateZ(150px);
  58. }
  59. .box .right{
  60. /*background-color: red;*/
  61. transform: rotateY(90deg) translateZ(150px);
  62. }
  63. .box .top{
  64. /*background-color: deepskyblue;*/
  65. transform: rotateX(90deg) translateZ(150px);
  66. }
  67. .box .bottom{
  68. /*background-color: purple;*/
  69. transform: rotateX(-90deg) translateZ(150px);
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <div>
  75. <div></div>
  76. <div></div>
  77. <div></div>
  78. <div></div>
  79. <div></div>
  80. <div></div>
  81. </div>
  82. <script src="jquery.js"></script>
  83. <script>
  84. var box = $(".box");
  85. var divs = box.children();
  86. var lisColor = ['deeppink','yellow','greenyellow','red','deepskyblue','purple']
  87. divs.each(function(index,el){
  88. var ul = $("<ul></ul>");
  89. for(var i = 0; i < 9; i++){
  90. var li = $("<li></li>");
  91. li.css({"backgroundColor":lisColor[index]});
  92. ul.append(li);
  93. }
  94. $(el).append(ul);
  95. });
  96. var lisPosition = [];
  97. for(var i = 0; i < 54; i++){
  98. lisPosition.push(parseInt(Math.random()*350));
  99. }
  100. $('li').each(function(index,el){
  101. $(el).css({'left':lisPosition[index],"top":lisPosition[index]});
  102. })
  103. $('li').each(function(index,el){
  104. $(el).animate({'left':0,"top":0},3000);
  105. })
  106. </script>
  107. </body>
  108. </html>

相关推荐:

如何使用纯CSS实现一只会动的手(附源码)

如何使用纯CSS实现一把剪刀的效果(附源码)

以上就是如何使用css3实现魔方的动画效果(完整代码)的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行