<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#app {
width: 100px;
height: 100px;
border-radius: 50%;
margin: auto;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
const app = document.getElementById("app");
const sleep = time => new Promise(resovle => setTimeout(resovle, time??0))
app.changeColor = async function (color, time) {
this.style.backgroundColor = color;
await sleep(time);
}
var main = async () => {
while (true) {
await app.changeColor('red', 1000);
await app.changeColor('green', 1500);
await app.changeColor('yellow', 500);
}
}
main();
</script>
</body>
</html>
tips
@wx:qq981145483