当前位置:   article > 正文

css实现图片的3d旋转-照片墙_css3d旋转照片墙【

css3d旋转照片墙【

一.效果图

 

二.图片摆放

1.html        

        这里准备了1个section和7个div,7个div都要求定位在父元素section那里(都在中心点),每个div各一张图,上面效果图有1张在中间的,其余6张图要在周围

  1. <section>
  2. <div></div>
  3. <div></div>
  4. <div></div>
  5. <div></div>
  6. <div></div>
  7. <div></div>
  8. <div></div>
  9. </section>

2.图片位置摆放-旋转

         6个图片在周围,看起来就像个六边形,所以每个图都间隔60度,依次旋转就是(0° 60° 120° 180° 240° 300°)

  1. section div:nth-of-type(1){
  2. transform:rotateY(0deg);
  3. background:url(DSC02240.jpg) no-repeat;
  4. background-size:220px 350px;
  5. }
  6. section div:nth-of-type(2){
  7. transform:rotateY(60deg);
  8. background:url(DSC02249.jpg) no-repeat;
  9. background-size:220px 350px;
  10. }/*其余类似*/

记得给body加上3d透视效果    perspective:1450px(3d视觉效果)

还有section加上内嵌效果    transform-style:preserve-3d(所有子元素在3D空间中呈现)

2.图片位置摆放-旋转

        想象一下从上面往下看,此时图片就被内嵌在一起,像米字形一样,这时候需要让每个图片在z轴添加一个距离(旋转后方向已改变,图片正前方就是z轴的方向) 

transform:translateZ(400px);

        此时图片位置已经做完

三.动画效果

        让大盒子section 360度无限循环的转起来

  1. @keyframes rotations{
  2. /* 添加动画效果 */
  3. 0%{}
  4. 100%{
  5. transform:rotateY(360deg);
  6. }
  7. }

        动画在赋予seciton

  1. section{
  2. animation:rotations 10s linear infinite; /*infinite:无限循环*/
  3. }

四.代码展示

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>view</title>
  6. <style>
  7. body{
  8. /*添加3d透视效果*/
  9. perspective:1450px;
  10. background-color:#000;
  11. }
  12. section{
  13. position:relative;
  14. margin:220px auto;
  15. width:220px;
  16. height:350px;
  17. animation:rotations 10s linear infinite;
  18. /*所有子元素在3D空间中呈现*/
  19. transform-style:preserve-3d;
  20. }
  21. section div{
  22. position:absolute;
  23. left:0;
  24. top:0;
  25. width:100%;
  26. height:100%;
  27. }
  28. /*先旋转在移动*/
  29. section div:nth-of-type(1){
  30. transform:rotateY(0deg) translateZ(400px);
  31. background:url(DSC02240.jpg) no-repeat;
  32. background-size:220px 350px;
  33. }
  34. section div:nth-of-type(2){
  35. transform:rotateY(60deg) translateZ(400px);
  36. background:url(DSC02249.jpg) no-repeat;
  37. background-size:220px 350px;
  38. }
  39. section div:nth-of-type(3){
  40. transform:rotateY(120deg) translateZ(400px);
  41. background:url(DSC02308.jpg) no-repeat;
  42. background-size:220px 350px;
  43. }
  44. section div:nth-of-type(4){
  45. transform:rotateY(180deg) translateZ(400px);
  46. background:url(DSC02323.jpg) no-repeat;
  47. background-size:220px 350px;
  48. }
  49. section div:nth-of-type(5){
  50. transform:rotateY(240deg) translateZ(400px);
  51. background:url(DSC02345.jpg) no-repeat;
  52. background-size:220px 350px;
  53. }
  54. section div:nth-of-type(6){
  55. transform:rotateY(300deg) translateZ(400px);
  56. background:url(DSC02268.jpg) no-repeat;
  57. background-size:220px 350px;
  58. }
  59. section div:nth-of-type(7){
  60. background:url(DSC02746.JPG) no-repeat;
  61. background-size:220px 350px;
  62. }
  63. @keyframes rotations{
  64. /* 添加动画效果 */
  65. 0%{}
  66. 100%{
  67. transform:rotateY(360deg);
  68. }
  69. }
  70. section:hover{
  71. /* 鼠标放入动画即停止 */
  72. animation-play-state:paused;
  73. }
  74. section div:hover{
  75. box-shadow:0 0 38px #169FE6; /* 鼠标放入显示阴影 */
  76. }
  77. </style>
  78. </head>
  79. <body>
  80. <section>
  81. <div></div>
  82. <div></div>
  83. <div></div>
  84. <div></div>
  85. <div></div>
  86. <div></div>
  87. <div></div>
  88. </section>
  89. </body>
  90. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/450851
推荐阅读
相关标签
  

闽ICP备14008679号