<div @mousedown="mousedown" id="dragbox" class="dragbox"> </div> mousedown(event) { this.selectElement = document.getElementById("dragbox"); var div1 = this.selectElement; this.selectElement.style.cursor = "move"; this.isDowm = true; var distanceX = event.clientX - this.selectElement.offsetLeft; var distanceY = event.clientY - this.selectElement.offsetTop; document.onmousemove = function(ev) { var oevent = ev || event; div1.style.left = oevent.clientX - distanceX + "px"; div1.style.top = oevent.clientY - distanceY + "px"; }; document.onmouseup = function() { document.onmousemove = null; document.onmouseup = null; div1.style.cursor = "default"; }; },
原文地址:https://www.cnblogs.com/amadoGrowers/p/12192298.html
时间: 2024-10-08 08:55:11