17.照片墙.html 2.4 KB

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