|
|

楼主 |
发表于 2022-9-14 06:59
|
显示全部楼层
本帖最后由 马黑黑 于 2022-9-14 07:04 编辑
珠子特效代码:
一、CSS:
.ball {
--ss: 0s;
position: absolute;
width: 10px;
height: 10px;
left: 346px;
top: 300px;
border-radius: 50%;
background: red;
offset-distance: 0;
offset-path: path("M150 60 Q245 -10 280 60 Q320 150 150 290 Q-20 150 20 60 Q65 -10 150 60z");
animation: move 6s var(--ss) linear infinite;
}
@keyframes move { to { offset-distance: 100%;} }
二、HTML:确保有 id="papa" 的父元素(也可以修改JS重命名父元素id
三、JS:
let setColor = () => Math.random().toString(16).substr(-6); //生成随机16进制颜色
//生成珠子
Array.from({length: 60}).forEach((ele,key) => {
ele = document.createElement('span');
ele.className = 'ball';
ele.style.cssText += `--ss: ${key * 0.1}s; background: #${setColor()};`;
papa.appendChild(ele);
});
|
|