|
|

楼主 |
发表于 2023-7-4 12:35
|
显示全部楼层
代码
- <style>
- #mama {
- width: 1000px;
- height: 600px;
- background: linear-gradient(to top right,darkgreen,antiquewhite);
- opacity: .95;
- overflow: hidden;
- position: relative;
- margin: 0 0 0 calc(50% - 581px);
- }
- li-zi {
- display: block;
- position: absolute;
- width: 10px;
- height: 10px;
- background: snow;
- border-radius: 50%;
- }
- </style>
- <div id="mama"></div>
- <script>
- let total = 50, canMove = true, lzAr = [];
- let mlAr = Array.from({length: total}, (v) => Math.random() * 1.5 - .8),
- mtAr = Array.from({length: total}, (v) => Math.random() * 1.2 - .6);
- Array.from({length: total}).forEach((item,key) => {
- item = document.createElement('li-zi');
- let ww = 4 + Math.round(Math.random() * 10),
- lPos = Math.round(Math.random() * (mama.offsetWidth - ww)),
- tPos = Math.round(Math.random() * (mama.offsetHeight - ww));
- item.style.cssText += `
- left: ${lPos}px;
- top: ${tPos}px;
- width: ${ww}px;
- height: ${ww}px;
- background: #${Math.random().toString(16).substr(-6)};
- `;
- let ar = [item,lPos,tPos,ww];
- lzAr.push(ar);
- mama.appendChild(item);
- });
- let move = () => {
- if(canMove) {
- lzAr.forEach((item,key) => {
- item[1] += mlAr[key];
- item[2] += mtAr[key];
- if(item[1] > mama.offsetWidth) item[1] = 0;
- if(item[1] < -item[3] / 2) item[1] = mama.offsetWidth;
- if(item[2] > mama.offsetHeight) item[2] = 0;
- if(item[2] < -item[3] / 2) item[2] = mama.offsetHeight;
- item[0].style.left = item[1] + 'px';
- item[0].style.top = item[2] + 'px';
- });
- }
- requestAnimationFrame(move);
- };
- move();
- </script>
复制代码
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
小辣椒
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|