1, the goal is to achieve DIV follow the mouse and move, in three different situations to achieve
A) first get Div, to bind the mouse movement event, to the div to open the positioning function
The first implementation, if the body size is the same as the page size, you can use this method.
1) Get the coordinates of the mouse, and give the div coordinate assignment, realize as follows:
var left = Event.clientx;var top = Event.clienty;box1.style.left = left + "px"; box1.style.top = top + "px";
The second way, if the body height is greater than the visible height, then the scroll bar will appear, Clientxy get the visible size, then the extra parts will not be able to move, you need to use the following way to implement
However, this approach is incompatible with IE8, so if you want to be compatible with IE8, you cannot use it. Pagex is to get the entire page size
var left = Event.pagex;var top = event.pagey;
The third way is what can be compatible, covering the above two methods of feasibility, that is, with the visible window plus the height of the scrollbar can be
var st = Document.body.scrollTop | | Document.documentelement.scrolltop;var left = Event.clientx;var top = Event.clienty;box1.style.left = left + "px"; Box1.style.top = top + st+ "px";
Note that the left axis is the same, I just realized the y-axis here
Div follows Mouse move