Here is the POJS equivalent of other answers that cross-reference IE 6 (and probably IE 5, but I don't have it anymore). No global variables:
function addEvent(el, evt, fn) { if (el.addEventListener) { el.addEventListener(evt, fn, false); } else if (el.attachEvent) { el.attachEvent('on' + evt, fn); } } (function () { var x, y; window.onload = function() { addEvent(document.body, 'mousemove', function(e) {
But there are big problems. Key events are dispatched only if the element that can receive keyboard input is focused (input, text field, etc.). Also, if the user scrolls the screen without moving the mouse, the coordinates are likely to be incorrect.
An alternative solution is to use CSS to replace the cursor with custom animations.
source share