老师,请帮忙检查一下错误

来源:3-3 then()-2

张艺兴的宝贝

2022-10-24 09:34:39

<!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>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 300px;
            height: 300px;
            background-color: aqua;
            transition: all 0.5s;
        }
    </style>
</head>

<body>
    <div id="box"></div>
<script>
const move = (el, {
            x = 0,
            y = 0
        } = {}, end = () => {}) => {
            el.style.transform = `transform3d(${x}px,${y}px,0)`;
            el.addEventListener('transitionend', () => {
                end();
            }, false)
        };
        const box = document.getElementById('box');
        const movePromise = (el, point) => {
            return new Promise(resolve => {
                move(el, point, () => {
                    resolve();
                })
            });
        };
        document.addEventListener('click', () => {
            movePromise(box, {
                x: 150
            }).then(() => {
                return movePromise(box, {
                    x: 150,
                    y: 150
                });
            }).then(() => {
                return movePromise(box, {
                    y: 150
                });
            }).then(() => {
                return movePromise(box, {
                    x: 0,
                    y: 0
                })
            });
        }, false)
 </script>
</body>


写回答

1回答

imooc_慕慕

2022-10-24

同学你好,分析如下:

单词拼写错误导致无效果,参考修改如下:

https://img.mukewang.com/climg/6355f6cc09af272805900187.jpg

祝学习愉快~

0

0 学习 · 17877 问题

查看课程