| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <!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>
- img {
- position: absolute;
- /* width: 200px; */
- }
- </style>
- </head>
- <body>
- <!-- <img src="./img/1.png" alt=""> -->
- <script>
- var screenWidth = document.body.clientWidth || document.documentElement.clientWidth;
- var screenHeight = document.body.clientHeight || document.documentElement.clientHeight;
- function Leaf() {
- this.width = Math.round(Math.random() * 100 + 100);
- this.top = 0;
- this.left = Math.random() * (screenWidth - this.width);
- this.urls = './img/'+ Math.floor(Math.random() * 4 + 1) +'.png'
- }
- // 绘制图片
- Leaf.prototype.init = function() {
- var imgs = document.createElement('img');
- imgs.src = this.urls;
- imgs.style.width = this.width + 'px';
- imgs.style.left = this.left + 'px';
- imgs.style.top = this.top + 'px';
- document.body.appendChild(imgs);
- }
- // 展示图片
- for(let i=0;i<20;i++) {
- let leaf = new Leaf();
- leaf.init();
- }
- </script>
- </body>
- </html>
|