Js implements a simple method for mouse follow, js implements mouse follow
This article describes how to implement simple mouse-following in JavaScript. Share it with you for your reference. The specific analysis is as follows:
As the name implies, when the mouse moves, an animation moves along with the mouse.
Key Aspect 1:
var oEvent = evt || window.event;
This is written to be compatible with ie and ff. in ie, window. event indicates the event object, while in ff, a parameter is passed to the event function, which indicates the event object.
Key Aspect 2:
document.onmousemove = function(evt)
Mouse following occurs when the mouse moves.
Key Aspect 3:
document.documentElement.scrollTop || document.body.scrollTop;
This is to be compatible with chrome and other browsers. the scroll bar is the scroll distance from the top. chrome uses the back one, and other browsers use the front one.
Key Aspect 4:
oTop.style.top=oEvent.clientY+scrolltop+10+"px";
When the mouse moves, the current position of the mouse is assigned to the position value of the element.
OEvent. clientY is the position of the current Y coordinate of the mouse. The scrolltop distance is to be written without changing the effect of the mouse following when the scroll is not the first screen.
The Code is as follows:
<! DOCTYPE html>
I hope this article will help you design javascript programs.