21.照片墙.html 2.4 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, .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. /**
  53. * 0 1 2 3 4 5
  54. * 6 7 8 9 10 11
  55. * 12 13 14 15 16 17
  56. * 18 19 20 21 22 23
  57. */
  58. //获取屏幕宽高
  59. var screenHeight = document.body.clientHeight || document.documentElement.clientHeight;
  60. var screenWidth = document.body.clientWidth || document.documentElement.clientWidth;
  61. // 间隙
  62. var gapX = (screenWidth - 120*6)/7;
  63. var gapY = (screenHeight - 120*4)/5;
  64. for(var i=0;i<imgList.length;i++) {
  65. var row = Math.floor(i/6) + 1;
  66. var col = i % 6 + 1;
  67. imgList[i].style.top = row * gapY + (row-1) * 120 + 'px';
  68. imgList[i].style.left = col * gapX + (col-1) * 120 + 'px';
  69. imgList[i].style.transitionDelay = (23-i) * 100 + 'ms';
  70. imgList[i].style.transform = 'rotate(' + Math.random()*40+'deg)';
  71. }
  72. </script>
  73. </body>
  74. </html>