<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Promise 是什么</title>
<style>
* {
padding: 0;
margin: 0;
}
#box {
width: 300px;
height: 300px;
background-color: olivedrab;
transition: all 0.5s;
}
</style>
</head>
<body>
<div id="box"></div>
</body>
<script>
var div = document.getElementById("box");
div.onclick = function () {
div.style.transform = "translate(150px,0px)";
setTimeout(function () {
div.style.transform = "translate(150px,150px)";
setTimeout(function () {
div.style.transform = "translate(0px,150px)";
setTimeout(function () {
div.style.transform = "translate(0px,0px)";
}, 500);
}, 500);
}, 500);
};
div.onclick = function () {
div.style.transform = "translate(150px,0px)";
div.ontransitionend = function () {
div.style.transform = "translate(150px,150px)";
div.ontransitionend = function () {
div.style.transform = "translate(0px,150px)";
div.ontransitionend = function () {
div.style.transform = "translate(0px,0px)";
};
};
};
};
</script>
</html>