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)
类似如此,封装函数后,直接调用此函数
浙公网安备 33010602011771号