滑鼠拖拽就是
在滑鼠點擊時呼叫滑鼠移動,滑鼠抬起失去滑鼠移動時間
可以寫一個偽代碼
mousedown
var offsetX = e.clientX - node.offsetLeft; //offsetX 為滑鼠與元素的橫坐標差
var offsetY = e.clientY - node.offsetTop; //offsetY 為滑鼠與元素的縱坐標差
mousemove
node.style.left = e.clientX - offsetX + 'px';
node.style.top = e.clientY - offsetY + 'px';
mouseup
document.onmousemove = null;
原代碼:


前端小白,僅供自己學習,還望大佬多多提出問題
uj5u.com熱心網友回復:
拖拽距離=滑鼠移動距離uj5u.com熱心網友回復:
https://blog.csdn.net/weixin_41910848/article/details/82218243uj5u.com熱心網友回復:
是嘞,我知道我就沒寫了轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/10663.html
標籤:JavaScript
