Q1 纯css写个呼吸灯动画

@keyframes breathing {
0% { opacity: 0.3; }
50% { opacity: 1; }
100% { opacity: 0.3; }
}

.breathing-light {
width: 100px;
height: 100px;
background-color: yellow;
animation: breathing 2s infinite;
}

Q2 用js写个函数要求随机一到三秒内返回一个promise对象,低于两秒成功,超过两秒失败

function randomPromise() {
return new Promise((resolve, reject) => {
const randomTime = Math.floor(Math.random() * 3000) + 1000; // 生成1到3秒之间的随机时间
setTimeout(() => {
if (randomTime < 2000) {
resolve('成功');
} else {
reject('失败');
}
}, randomTime);
});
}

// 测试示例
randomPromise()
.then((result) => {
console.log(result); // 成功
})
.catch((error) => {
console.log(error); // 失败
});