14.照片墙.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. body {
  9. background: #ccc;
  10. }
  11. img {
  12. width: 120px;
  13. height: 120px;
  14. position: absolute;
  15. top: -120px;
  16. left: -120px;
  17. transition: all 2s ease-out;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <img src="./images/1.jpg" alt="">
  23. <img src="./images/2.jpg" alt="">
  24. <img src="./images/3.jpg" alt="">
  25. <img src="./images/4.jpg" alt="">
  26. <img src="./images/5.jpg" alt="">
  27. <img src="./images/6.jpg" alt="">
  28. <img src="./images/7.jpg" alt="">
  29. <img src="./images/8.jpg" alt="">
  30. <img src="./images/9.jpg" alt="">
  31. <img src="./images/10.jpg" alt="">
  32. <img src="./images/11.jpg" alt="">
  33. <img src="./images/12.jpg" alt="">
  34. <img src="./images/13.jpg" alt="">
  35. <img src="./images/14.jpg" alt="">
  36. <img src="./images/15.jpg" alt="">
  37. <img src="./images/16.jpg" alt="">
  38. <img src="./images/17.jpg" alt="">
  39. <img src="./images/18.jpg" alt="">
  40. <img src="./images/19.jpg" alt="">
  41. <img src="./images/20.jpg" alt="">
  42. <img src="./images/21.jpg" alt="">
  43. <img src="./images/22.jpg" alt="">
  44. <img src="./images/23.jpg" alt="">
  45. <img src="./images/24.jpg" alt="">
  46. <script>
  47. const imgList = document.querySelectorAll("img");
  48. const screenWidth = document.documentElement.clientWidth || document.body.clientWidth;
  49. const screenHeight = document.documentElement.clientHeight || document.body.clientHeight;
  50. /**
  51. * 0 1 2 3 4 5
  52. * 6 7 8 9 10 11
  53. * 12 13 14 15 16 17
  54. * 18 19 20 21 22 23
  55. */
  56. const x = (screenWidth - 120 * 6) / 7;
  57. const y = (screenHeight - 120 * 4) / 5;
  58. for (let i = 0; i < imgList.length; i++) {
  59. const row = Math.floor(i / 6) + 1;
  60. const col = i % 6 + 1;
  61. imgList[i].style.top = row * y + (row - 1) * 120 + 'px';
  62. imgList[i].style.left = col * x + (col - 1) * 120 + 'px';
  63. imgList[i].style.transitionDelay = (23 - i) * 100 + 'ms';
  64. imgList[i].style.transform = 'rotate(' + Math.random() * 180 + 'deg)'
  65. }
  66. </script>
  67. </body>
  68. </html>