|
|

楼主 |
发表于 2023-7-8 07:07
|
显示全部楼层
帖子代码
- <style>
- #mama {
- margin: 0 0 0 calc(50% - 593px);
- position: relative;
- z-index: 1;
- width: 1024px;
- height: 644px;
- background: #333 url('https://638183.freep.cn/638183/t23/2/004.jpg');
- box-shadow: 0 0 6px #000;
- pointer-events: none;
- --state: paused;
- }
- #mama::before {
- position: absolute;
- content: '\1F3F5';
- font: normal 60px/60px sans-serif;
- color: antiquewhite;
- cursor: pointer;
- left: calc(50% - 28px);
- bottom: 6px;
- animation: rot 6s infinite linear var(--state);
- pointer-events: auto;
- }
- li-zi {
- position: absolute;
- border-radius: 50%;
- opacity: .75;
- transition: background .6s;
- }
- @keyframes rot { to { transform: rotate(360deg); } }
- </style>
- <div id="mama"></div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=27937361" autoplay="autoplay" loop="loop"></audio>
- <script>
- (function() {
- let canMove = false;
- class Lizi {
- constructor(pa,size = 20) {
- this.pa = pa;
- this.size = size;
- this.left = 10;
- this.top = 10;
- this.xstep = 1;
- this.ystep = 1;
- this.ele = document.createElement('li-zi');
- }
- creating() {
- this.ele.style.cssText = `
- width: ${this.size}px;
- height: ${this.size}px;
- left: ${this.left}px;
- top: ${this.top}px;
- background: ${this.bg};
- `;
- this.pa.appendChild(this.ele);
- this.setBg();
- this.moving();
- }
- moving() {
- if(canMove) {
- this.left += this.xstep;
- this.top += this.ystep;
- if(this.left <= 0 || this.left >= this.pa.offsetWidth - this.size) {
- this.xstep = -this.xstep;
- this.setBg();
- }
- if(this.top <= 0 || this.top >= this.pa.offsetHeight - this.size) {
- this.ystep = -this.ystep;
- this.setBg();
- }
- this.ele.style.left = this.left + 'px';
- this.ele.style.top = this.top + 'px';
- }
- requestAnimationFrame(this.moving.bind(this));
- }
- setBg() {
- this.ele.style.background = '#' + Math.random().toString(16).substr(-6);
- }
- }
- let stepAr = [0.5,-0.5,1,-1,0.8,-0.8,1.2,-1.2,0.3,-0.3,1.5,-1.5]; //步幅数组
- Array.from({length: 60}).forEach((element) => {
- let xIdx = Math.floor(Math.random() * stepAr.length), yIdx = Math.floor(Math.random() * stepAr.length);
- element = new Lizi(mama);
- element.size = 8 + Math.ceil(Math.random() * 20);
- element.left = Math.floor(Math.random() * (mama.offsetWidth - element.size));
- element.top = Math.floor(Math.random() * (mama.offsetHeight - element.size));
- element.xstep = stepAr[xIdx];
- element.ystep = stepAr[yIdx];
- element.creating();
- });
- let mState = () => aud.paused ? (mama.style.setProperty('--state','paused'),canMove = false) : (mama.style.setProperty('--state','running'),canMove = true);
- aud.addEventListener('play', mState, false);
- aud.addEventListener('pause', mState, false);
- mama.onclick = () => aud.paused ? aud.play() : aud.pause();
- })();
- </script>
复制代码
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|