3D立体动态相册实现代码

红太狼 2020-05-20 02:35 1153阅读 1赞

今天是情人节,2020-05-20日,身为一名扣脚的程序员必须要拿出点真本事了。知道为什么程序为啥找不到女朋友吗?那么我就告诉你程序员是怎么送女朋友礼物的。

正文:
一、用记事本新建一个text然后件文件名包括后缀都删除掉改成dandelioncloud.html的文件,然后把下面的代码复制进来。代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>纯CSS实现鼠标经过3D立体动态展示图片特效代码 - 蒲公英云</title>
  6. <link type="text/css" href="css/style.css" rel="stylesheet" />
  7. </head>
  8. <body>
  9. <div class="box">
  10. <ul class="minbox">
  11. <li></li>
  12. <li></li>
  13. <li></li>
  14. <li></li>
  15. <li></li>
  16. <li></li>
  17. </ul>
  18. <ol class="maxbox">
  19. <li></li>
  20. <li></li>
  21. <li></li>
  22. <li></li>
  23. <li></li>
  24. <li></li>
  25. </ol>
  26. </div>
  27. </body>
  28. </html>

二、再次新建一个txt修改txt为:style.css然后把下面的css复制进去保存。css样式的代码

  1. @charset "utf-8";
  2. *{
  3. margin:0;
  4. padding:0;
  5. }
  6. body{
  7. max-width: 100%;
  8. min-width: 100%;
  9. height: 100%;
  10. background-size: cover;
  11. background-repeat: no-repeat;
  12. background-attachment: fixed;
  13. background-size:100% 100%;
  14. position: absolute;
  15. margin-left: auto;
  16. margin-right: auto;
  17. }
  18. li{
  19. list-style: none;
  20. }
  21. .box{
  22. width:200px;
  23. height:200px;
  24. background-size: cover;
  25. background-repeat: no-repeat;
  26. background-attachment: fixed;
  27. background-size:100% 100%;
  28. position: absolute;
  29. margin-left: 42%;
  30. margin-top: 22%;
  31. -webkit-transform-style:preserve-3d;
  32. -webkit-transform:rotateX(13deg);
  33. -webkit-animation:move 5s linear infinite;
  34. }
  35. .minbox{
  36. width:100px;
  37. height:100px;
  38. position: absolute;
  39. left:50px;
  40. top:30px;
  41. -webkit-transform-style:preserve-3d;
  42. }
  43. .minbox li{
  44. width:100px;
  45. height:100px;
  46. position: absolute;
  47. left:0;
  48. top:0;
  49. }
  50. .minbox li:nth-child(1){
  51. background: url(../img/01.png) no-repeat 0 0;
  52. -webkit-transform:translateZ(50px);
  53. }
  54. .minbox li:nth-child(2){
  55. background: url(../img/02.png) no-repeat 0 0;
  56. -webkit-transform:rotateX(180deg) translateZ(50px);
  57. }
  58. .minbox li:nth-child(3){
  59. background: url(../img/03.png) no-repeat 0 0;
  60. -webkit-transform:rotateX(-90deg) translateZ(50px);
  61. }
  62. .minbox li:nth-child(4){
  63. background: url(../img/04.png) no-repeat 0 0;
  64. -webkit-transform:rotateX(90deg) translateZ(50px);
  65. }
  66. .minbox li:nth-child(5){
  67. background: url(../img/05.png) no-repeat 0 0;
  68. -webkit-transform:rotateY(-90deg) translateZ(50px);
  69. }
  70. .minbox li:nth-child(6){
  71. background: url(../img/06.png) no-repeat 0 0;
  72. -webkit-transform:rotateY(90deg) translateZ(50px);
  73. }
  74. .maxbox li:nth-child(1){
  75. background: url(../img/1.png) no-repeat 0 0;
  76. -webkit-transform:translateZ(50px);
  77. }
  78. .maxbox li:nth-child(2){
  79. background: url(../img/2.png) no-repeat 0 0;
  80. -webkit-transform:translateZ(50px);
  81. }
  82. .maxbox li:nth-child(3){
  83. background: url(../img/3.png) no-repeat 0 0;
  84. -webkit-transform:rotateX(-90deg) translateZ(50px);
  85. }
  86. .maxbox li:nth-child(4){
  87. background: url(../img/4.png) no-repeat 0 0;
  88. -webkit-transform:rotateX(90deg) translateZ(50px);
  89. }
  90. .maxbox li:nth-child(5){
  91. background: url(../img/5.png) no-repeat 0 0;
  92. -webkit-transform:rotateY(-90deg) translateZ(50px);
  93. }
  94. .maxbox li:nth-child(6){
  95. background: url(../img/6.png) no-repeat 0 0;
  96. -webkit-transform:rotateY(90deg) translateZ(50px);
  97. }
  98. .maxbox{
  99. width: 800px;
  100. height: 400px;
  101. position: absolute;
  102. left: 0;
  103. top: -20px;
  104. -webkit-transform-style: preserve-3d;
  105. }
  106. .maxbox li{
  107. width: 200px;
  108. height: 200px;
  109. background: #fff;
  110. border:1px solid #ccc;
  111. position: absolute;
  112. left: 0;
  113. top: 0;
  114. opacity: 0.2;
  115. -webkit-transition:all 1s ease;
  116. }
  117. .maxbox li:nth-child(1){
  118. -webkit-transform:translateZ(100px);
  119. }
  120. .maxbox li:nth-child(2){
  121. -webkit-transform:rotateX(180deg) translateZ(100px);
  122. }
  123. .maxbox li:nth-child(3){
  124. -webkit-transform:rotateX(-90deg) translateZ(100px);
  125. }
  126. .maxbox li:nth-child(4){
  127. -webkit-transform:rotateX(90deg) translateZ(100px);
  128. }
  129. .maxbox li:nth-child(5){
  130. -webkit-transform:rotateY(-90deg) translateZ(100px);
  131. }
  132. .maxbox li:nth-child(6){
  133. -webkit-transform:rotateY(90deg) translateZ(100px);
  134. }
  135. .box:hover ol li:nth-child(1){
  136. -webkit-transform:translateZ(300px);
  137. width: 400px;
  138. height: 400px;
  139. opacity: 0.8;
  140. left: -100px;
  141. top: -100px;
  142. }
  143. .box:hover ol li:nth-child(2){
  144. -webkit-transform:rotateX(180deg) translateZ(300px);
  145. width: 400px;
  146. height: 400px;
  147. opacity: 0.8;
  148. left: -100px;
  149. top: -100px;
  150. }
  151. .box:hover ol li:nth-child(3){
  152. -webkit-transform:rotateX(-90deg) translateZ(300px);
  153. width: 400px;
  154. height: 400px;
  155. opacity: 0.8;
  156. left: -100px;
  157. top: -100px;
  158. }
  159. .box:hover ol li:nth-child(4){
  160. -webkit-transform:rotateX(90deg) translateZ(300px);
  161. width: 400px;
  162. height: 400px;
  163. opacity: 0.8;
  164. left: -100px;
  165. top: -100px;
  166. }
  167. .box:hover ol li:nth-child(5){
  168. -webkit-transform:rotateY(-90deg) translateZ(300px);
  169. width: 400px;
  170. height: 400px;
  171. opacity: 0.8;
  172. left: -100px;
  173. top: -100px;
  174. }
  175. .box:hover ol li:nth-child(6){
  176. -webkit-transform:rotateY(90deg) translateZ(300px);
  177. width: 400px;
  178. height: 400px;
  179. opacity: 0.8;
  180. left: -100px;
  181. top: -100px;
  182. }
  183. @keyframes move{
  184. 0%{
  185. -webkit-transform: rotateX(13deg) rotateY(0deg);
  186. }
  187. 100%{
  188. -webkit-transform:rotateX(13deg) rotateY(360deg);
  189. }
  190. }

三、文件的目录结构,把css文件放到css文件夹里,图片放到img文件夹里。

四、如果图片尺寸不会修改的话,可以选择使用美图秀秀网页版很简单,可以在线调整尺寸。然后保存到本地磁盘。

五、容易出现的问题 ,图片展示不全或展示的方向不对

1.图片尺寸需要修改 (解决展示不全的情况)

上图是我的图片文件夹里放的图片 ,首先01-06编号命名的图片尺寸是100x100px的大小的,1-6编号是400x400px,如果效果想展示最佳,100x100px的图片是以头部特写的照片最好,因为01-06是立体照片内部小正方体的照片,1-6编号是外部正方体的照片。

2.图片的方向需要修改(解决头朝下的问题)

修改的方向如上图展示所示,比如第三张头就应该朝下,否则形成的效果图像会出现头是倒着的情况。

六、放一下动态效果图

总结:

创建dandelioncloud.html拷贝html保存。html完成。

创建创建 css文件夹 ,在创建好的css文件夹里创建style.css复制css样式到style.css里保存。css完成。

创建img文件夹,把处理好的图片素材放到img文件夹里面。(需要注意的是图片的名称格式一定要和html中的图片格式对上。)

最后双击dandelioncloud.html效果展示。完成。

发表评论

表情:
评论列表 (有 0 条评论,1153人围观)

还没有评论,来说两句吧...

相关阅读