老师我这边把return都取消了,动画还是不受影响?怎么回事?按理说取消了都默认是成功状态,然后会混乱才对呀?不是很明白
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Promise</title>
<style>
* {
padding: 0;
margin: 0;
}
#box {
width: 300px;
height: 300px;
background: red;
transition: all 0.5s;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
const move = (ele, { x = 0, y = 0 } = {}, end = () => {}) => {
//移动
ele.style.transform = `translate3d(${x}px,${y}px, 0)`;
//添加监听
ele.addEventListener(
"transitionend",
() => {
end();
},
false
);
};
const box = document.getElementById("box");
const movePromise = (el, point) => {
return new Promise((reolve, reject) => {
move(el, point, () => {
reolve();
});
});
};
document.onclick = () => {
movePromise(box, { x: 150 })
.then(() => {
movePromise(box, { x: 150, y: 150 })
.then(() => {
movePromise(box, { x: 0, y: 150 })
.then(() => {
movePromise(box, { x: 0, y: 0 });
});
});
});
};
</script>
</body>
</html>
39
收起
正在回答 回答被采纳积分+1
2回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星