|
|

楼主 |
发表于 2022-7-9 19:22
|
显示全部楼层
代码:
- <style>
- #papa { margin: 50px auto 0; width: 720px; height: 600px; box-shadow: 4px 4px 24px #000; position: relative; }
- #hunter { position: absolute; width: 90px; height: 66px; transition: all 3s; z-index: 99; }
- #prey { position: absolute; width: 60px; height: 60px; background: #333 linear-gradient(120deg,purple,tan); border-radius: 50%; }
- </style>
- <div id="papa">
- <img id="hunter" alt="" src="/data/attachment/forum/202207/08/225900jzc7ctq9wa99r83a.gif" />
- <span id="prey"></span>
- </div>
- <script>
- let aniFlag = 1;
- let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
- setTimeout(gogo,100);
- function gogo() {
- let left = num(0,960), top = num(0,500);
- prey.style.left = left + 'px';
- prey.style.top = top + 'px';
- hunter.style.left = left + 'px';
- hunter.style.top = top + 'px';
- aniFlag == 1 ? (prey.style.opacity = '1', aniFlag = 0) : (prey.style.opacity = '0', aniFlag = 1);
- setTimeout(gogo,6000);
- }
- </script>
复制代码
|
|