css3实现一个有趣的海贼王人物3d旋转相册

左手的ㄟ右手 2021-12-10 17:19 462阅读 0赞

主要用到了CSS3中的 transform-style: preserve-3d; filter滤镜效果; nth-child选择器, figure标签;

transform 中的rotate(旋转)、translate(移动)等。

html代码:

  1. <h2>ONE PIECE 3D Images Gallery</h2>
  2. <div class="container">
  3. <div id="rotatephoto">
  4. <figure><img src="img/rotate1.jpg" alt=""></figure>
  5. <figure><img src="img/rotate2.jpg" alt=""></figure>
  6. <figure><img src="img/rotate3.jpg" alt=""></figure>
  7. <figure><img src="img/rotate4.jpg" alt=""></figure>
  8. <figure><img src="img/rotate5.jpg" alt=""></figure>
  9. <figure><img src="img/rotate6.jpg" alt=""></figure>
  10. <figure><img src="img/rotate7.jpg" alt=""></figure>
  11. <figure><img src="img/rotate8.jpg" alt=""></figure>
  12. <figure><img src="img/rotate9.jpg" alt=""></figure>
  13. </div>
  14. </div>

css代码:

gif.latex

  1. <style type="text/css">
  2. *{ margin: 0; padding: 0; outline: none; border: none; box-sizing: border-box; }
  3. html,body{ min-height: 100%; }
  4. body{ background-image: radial-gradient(mintcream 0%, lightgray 100%); }
  5. h2{
  6. display: table;
  7. margin: 5% auto 0;
  8. text-transform: uppercase; /* uppercase定义只有大写字母 */
  9. font-family: "Times New Roman",Georgia,Serif;
  10. font-size: 3em;
  11. font-weight: 500;
  12. text-shadow: 0 1px white, 0 3px blue;
  13. }
  14. .container{
  15. width: 360px;
  16. height: 250px;
  17. position: relative;
  18. margin: 5% auto;
  19. perspective: 1000;
  20. }
  21. #rotatephoto{
  22. width: 100%;
  23. height: 100%;
  24. position: absolute;
  25. transform-style: preserve-3d;
  26. animation: rotation 20s infinite linear;
  27. }
  28. #rotatephoto:hover{
  29. animation-play-state: paused;
  30. }
  31. #rotatephoto figure{
  32. display: block;
  33. position: absolute;
  34. width: 350px;
  35. height: 188px;
  36. left: 10px;
  37. top: 10px;
  38. background: black;
  39. overflow: hidden;
  40. border: 5px solid black;
  41. }
  42. #rotatephoto figure:nth-child(1){ transform: rotateY(0deg) translateZ(500px);}
  43. #rotatephoto figure:nth-child(2){ transform: rotateY(40deg) translateZ(500px);}
  44. #rotatephoto figure:nth-child(3){ transform: rotateY(80deg) translateZ(500px);}
  45. #rotatephoto figure:nth-child(4){ transform: rotateY(120deg) translateZ(500px);}
  46. #rotatephoto figure:nth-child(5){ transform: rotateY(160deg) translateZ(500px);}
  47. #rotatephoto figure:nth-child(6){ transform: rotateY(200deg) translateZ(500px);}
  48. #rotatephoto figure:nth-child(7){ transform: rotateY(240deg) translateZ(500px);}
  49. #rotatephoto figure:nth-child(8){ transform: rotateY(280deg) translateZ(500px);}
  50. #rotatephoto figure:nth-child(9){ transform: rotateY(320deg) translateZ(500px);}
  51. img{
  52. -webkit-filter: grayscale(1); /* filter滤镜 */
  53. cursor: pointer;
  54. transition: all 0.8s ease;
  55. }
  56. img:hover{
  57. -webkit-filter: grayscale(0);
  58. transform: scale(1.3, 1.3); /* scale缩放 */
  59. }
  60. @keyframes rotation{
  61. 0%{
  62. transform: rotateY(0deg);
  63. }
  64. 100%{
  65. transform: rotateY(360deg);
  66. }
  67. }
  68. </style>

附上效果动态图:

20190711172303557.gif

发表评论

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

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

相关阅读