123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
- body {
- background: rgba(0, 0, 0, .3);
- }
- img {
- width: 120px;
- height: 120px;
- position: absolute;
- top: -120px;
- left: -120px;
- transition: all 2s ease-out;
- }
- </style>
- </head>
- <body>
- <img src="./images/1.jpg" alt="">
- <img src="./images/2.jpg" alt="">
- <img src="./images/3.jpg" alt="">
- <img src="./images/4.jpg" alt="">
- <img src="./images/5.jpg" alt="">
- <img src="./images/6.jpg" alt="">
- <img src="./images/7.jpg" alt="">
- <img src="./images/8.jpg" alt="">
- <img src="./images/9.jpg" alt="">
- <img src="./images/10.jpg" alt="">
- <img src="./images/11.jpg" alt="">
- <img src="./images/12.jpg" alt="">
- <img src="./images/13.jpg" alt="">
- <img src="./images/14.jpg" alt="">
- <img src="./images/15.jpg" alt="">
- <img src="./images/16.jpg" alt="">
- <img src="./images/17.jpg" alt="">
- <img src="./images/18.jpg" alt="">
- <img src="./images/19.jpg" alt="">
- <img src="./images/20.jpg" alt="">
- <img src="./images/21.jpg" alt="">
- <img src="./images/22.jpg" alt="">
- <img src="./images/23.jpg" alt="">
- <img src="./images/24.jpg" alt="">
- <script>
- var imgList = document.querySelectorAll("img");
- /**
- * 0 1 2 3 4 5
- * 6 7 8 9 10 11
- * 12 13 14 15 16 17
- * 18 19 20 21 22 23
- */
- //获取屏幕宽高
- var screenHeight = document.body.clientHeight || document.documentElement.clientHeight;
- var screenWidth = document.body.clientWidth || document.documentElement.clientWidth;
- // 间隙
- var gapX = (screenWidth - 120*6)/7;
- var gapY = (screenHeight - 120*4)/5;
- for(var i=0;i<imgList.length;i++) {
- var row = Math.floor(i/6) + 1;
- var col = i % 6 + 1;
- imgList[i].style.top = row * gapY + (row-1) * 120 + 'px';
- imgList[i].style.left = col * gapX + (col-1) * 120 + 'px';
- imgList[i].style.transitionDelay = (23-i) * 100 + 'ms';
- imgList[i].style.transform = 'rotate(' + Math.random()*40+'deg)';
- }
- </script>
- </body>
- </html>
|