[js exercise] Move the position of the box, the mouse is outside the box

Click the box without loosening to follow the mouse movement, idea: subtract the coordinates of the mouse in the box from the coordinates of the mouse in the page to the left and top of a moving box

If the position of the box to be moved is written as position:relative, the mouse will be outside the box when the box moves with the mouse, so it needs to be changed to position:fixed.

position move:

absolute: relative to the nearest positioned parent element

relative: relative to its normal position

fixed: relative to the browser window

Guess you like

Origin blog.csdn.net/m0_67987829/article/details/124707387