Code demonstration:
http://www.imqing.com/demo/movediv.html
General principle:
Make the position of the div absolute, and then control Its top and left values need to monitor mouse events, mainly mousedown, mousemove, and mouseup.
After mousedown, record the position of the mouse and the div that needs to be moved during mousedown, and then get the difference between the two to get the position of the div after the mouse moves. That is:
left = current mouse position.x - (.x value when the mouse is clicked - x value of the initial position of the div)
top = current mouse position.y - (.y when the mouse is clicked value - the initial position y value of the div)
Code: