* {
margin: 0;
padding: 0;
}
img {
position: absolute;
}
<img src="../images/cangjingkong.jpg" alt="" id="img"/>
function my$(id) {
return document.getElementById(id);
}
var evt = {
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 (e) {
my$("img").style.left=evt.getPageX(e)+"px";
my$("img").style.top=evt.getPageY(e)+"px";
}
一段window.event和e的兼容代码,还有page的兼容代码,然后图片飘不起来,谷歌里面console也没有报错,请教各位大神指点一下,哪里出错了?