|
|

楼主 |
发表于 2025-7-6 21:26
|
显示全部楼层
本帖最后由 马黑黑 于 2025-7-6 22:57 编辑
代码:
- <div id="papa"></div>
- <script type="module">
- import TWEEN from 'https://638183.freep.cn/638183/3dev/examples/jsm/libs/tween.module.js';
- let sons = [], tweens = [], total = 10, time = 1000;
- Array.from({length: total}).forEach(son => {
- son = document.createElement('div');
- son.className = 'son';
- son.style.cssText += `
- transform: translate3d(0, 0, -1000px);
- background: linear-gradient(
- 35deg,
- #${Math.random().toString(16).substring(2,8)},
- #${Math.random().toString(16).substring(2,8)}
- );
- `;
- sons.push(son);
- papa.appendChild(son);
- });
- sons.forEach((son, key) => {
- const pos = { x: 0, z: -1000, a: 0 };
- const target = { x: papa.offsetWidth, z: 0, a: 30 };
- const tween = new TWEEN.Tween(pos)
- .to(target, time)
- .onUpdate( () => {
- son.style.setProperty('transform', `rotateZ(${pos.a}deg) translate3d( ${pos.x}px, 0, ${pos.z}px )`);
- })
- .onStart( () => {
- son.style.setProperty('opacity', 0.9);
- })
- .onComplete ( () => {
- setTimeout( () => {son.style.setProperty('opacity', 0); }, time);
- });
- tweens.push(tween);
- });
- tweens.forEach( (tween, key) => {
- tween.chain(tweens[(key + 1) % tweens.length]);
- });
- const animate = () => {
- TWEEN.update();
- requestAnimationFrame(animate);
- };
- tweens[0].start();
- animate();
- </script>
- <style>
- #papa {
- margin: auto;
- margin-top: 30px;
- width: 760px;
- height: 480px;
- border: 1px solid gray;
- perspective: 600px;
- position: relative;
- }
- .son {
- position: absolute;
- width: 60px;
- height: 60px;
- border-radius: 50%;
- background: linear-gradient(35deg, tan, skyblue);
- opacity: 0;
- filter: drop-shadow(4px 6px 8px gray);
- }
- </style>
复制代码
|
评分
-
| 参与人数 2 | 威望 +80 |
金钱 +160 |
经验 +80 |
收起
理由
|
花飞飞
| + 30 |
+ 60 |
+ 30 |
很给力! |
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|