20.照片墙.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. body {
  13. background: rgba(0, 0, 0, 0.3);
  14. }
  15. img {
  16. width: 120px;
  17. height: 120px;
  18. position: absolute;
  19. top: -120px;
  20. left: -120px;
  21. transition: all 2s ease-out;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <img src="./images/1.jpg" alt="" />
  27. <img src="./images/2.jpg" alt="" />
  28. <img src="./images/3.jpg" alt="" />
  29. <img src="./images/4.jpg" alt="" />
  30. <img src="./images/5.jpg" alt="" />
  31. <img src="./images/6.jpg" alt="" />
  32. <img src="./images/7.jpg" alt="" />
  33. <img src="./images/8.jpg" alt="" />
  34. <img src="./images/9.jpg" alt="" />
  35. <img src="./images/10.jpg" alt="" />
  36. <img src="./images/11.jpg" alt="" />
  37. <img src="./images/12.jpg" alt="" />
  38. <img src="./images/13.jpg" alt="" />
  39. <img src="./images/14.jpg" alt="" />
  40. <img src="./images/15.jpg" alt="" />
  41. <img src="./images/16.jpg" alt="" />
  42. <img src="./images/17.jpg" alt="" />
  43. <img src="./images/18.jpg" alt="" />
  44. <img src="./images/19.jpg" alt="" />
  45. <img src="./images/20.jpg" alt="" />
  46. <img src="./images/21.jpg" alt="" />
  47. <img src="./images/22.jpg" alt="" />
  48. <img src="./images/23.jpg" alt="" />
  49. <img src="./images/24.jpg" alt="" />
  50. <script>
  51. var imgList = document.querySelectorAll("img");
  52. var screenWidth =
  53. document.body.clientWidth || document.documentElement.clientWidth;
  54. var screenHeight =
  55. document.body.clientHeight || document.documentElement.clientHeight;
  56. /**
  57. * 0 1 2 3 4 5
  58. * 6 7 8 9 10 11
  59. * 12 13 14 15 16 17
  60. * 18 19 20 21 22 23
  61. */
  62. // 间隙大小
  63. var gapX = (screenWidth - 120 * 6) / 7;
  64. var gapY = (screenHeight - 120 * 4) / 5;
  65. for (var i = 0; i < imgList.length; i++) {
  66. //求出循环项在第几行第几列
  67. var row = Math.floor(i / 6) + 1;
  68. var col = (i % 6) + 1;
  69. // row: 2 ; col:4
  70. imgList[i].style.top = gapY * row + (row - 1) * 120 + "px";
  71. imgList[i].style.left = gapX * col + (col - 1) * 120 + "px";
  72. imgList[i].style.transitionDelay = (23 - i) * 100 + "ms";
  73. imgList[i].style.transform = 'rotate(' + Math.random() * 45 + 'deg)';
  74. }
  75. </script>
  76. </body>
  77. </html>