html函数封装

  JS函数的封装:定义函数后就要考虑函数的输入和输出

function move(obj) {
        obj.onmousedown = function (event) {
            const chaX = event.clientX - div1.offsetLeft
            const chaY = event.clientY - div1.offsetTop
            document.onmousemove = function (event) {
                obj.style.left = event.clientX - chaX + 'px'
                obj.style.top = event.clientY - chaY + 'px'
                crash(div1, div2)
            }
            document.onmouseup = function () {
                document.onmousemove = null
            }
        }
    }

    move(div1)
    move(div2)

  类似如此,封装函数后,直接调用此函数 

posted @ 2021-12-08 21:02  KimiRaikkonen  阅读(161)  评论(0)    收藏  举报