获取浏览器高度

1
2
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
console.log("浏览器窗口高度:" + windowHeight + " 像素");

获取屏幕高度

1
2
var screenHeight = window.screen.height;
console.log("屏幕高度:" + screenHeight + " 像素");

获取页面滚动的高度

1
2
var scrollHeight = window.scrollY || document.documentElement.scrollTop;
console.log("页面滚动高度:" + scrollHeight + " 像素");

获取鼠标所在位置

1
2
3
4
5
document.addEventListener("mousemove", function(event) {
var mouseX = event.clientX;
var mouseY = event.clientY;
console.log("鼠标位置:X=" + mouseX + ", Y=" + mouseY);
});