您的位置:首页 > Web前端 > JavaScript

获取鼠标位置的javascript(zz)

2008-12-19 19:30 357 查看
var Mouse = new function(){

this.x = 0;

this.y = 0;

this.capture = function(evt){

if (document.all) {// IE

Mouse.x = window.event.x + document.body.scrollLeft;

Mouse.y = window.event.y + document.body.scrollTop;

} else if (document.layers||document.getElementById) { // Netscape

Mouse.x = evt.pageX;

Mouse.y = evt.pageY;

}

//alert(Mouse.x + "/" + Mouse.y); //test

};

if (document.layers) { //netscape

document.captureEvents(Event.MOUSEMOVE);

}

document.onmousemove = this.capture;

};

var Screen = new function(){

if (document.layers||document.getElementById) { // Netscape

this.width = window.innerWidth+window.pageXOffset;

this.height = window.innerHeight+window.pageYOffset;

} else if (document.all) {// IE

this.width = document.body.clientWidth+document.body.scrollLeft;

this.height = document.body.clientHeight+document.body.scrollTop;

}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: