<!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>Document</title>
<style>
div {
width: 200px;
height: 200px;
background: olivedrab;
}
</style>
</head>
<body>
<div></div>
</body>
<script>
const div = document.querySelector("div");
const move = (obj, x, y) => {
obj.style.transform = `translate(${x}px,${y}px)`;
return new Promise((resolve) => {
obj.ontransitionend = () => {
resolve();
};
});
};
div.onclick = function () {
move(this, 150, 0)
.then(() => {
return move(this, 150, 150);
})
.then(() => {
return move(this, 0, 150);
})
.then(() => {
return move(this, 0, 0);
});
};
</script>
</html>