1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| var move = { getEvent: function (event) { return window.event || event; }, getClientX: function (event) { return this.getEvent(event).clientX; }, getClientY: function (event) { return this.getEvent(event).clientY; }, getScrollLeft: function () { return window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft || 0; }, getScrollTop: function () { return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0; }, getPageX: function (event) { return this.getEvent(event).pageX ? this.getEvent(event).pageX: this.getClientX(event) + this.getScrollLeft(); }, getPageY: function (event) { return this.getEvent(event).pageY ? this.getEvent(event).pageY: this.getClientY(event) + this.getScrollTop(); } };
document.onmousemove = function (event) { document.getElementById("img").style.left = move.getPageX(event)+"px"; document.getElementById("img").style.top = move.getPageY(event)+"px"; };
|