Skip to content

Instantly share code, notes, and snippets.

@hehongwei44
Created July 27, 2014 09:22
Show Gist options
  • Save hehongwei44/62907b9b7061d4defadb to your computer and use it in GitHub Desktop.
Save hehongwei44/62907b9b7061d4defadb to your computer and use it in GitHub Desktop.
页面 视口 滚动条的位置的辅助函数
/*确定当前页面高度和宽度的两个函数*/
function pageHeight() {
return document.body.scrollHeight;
}
function pageWidth() {
return document.body.scrollWidth;
}
/*确定滚动条水平和垂直的位置*/
function scrollX() {
var de = document.documentElement;
return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
}
function scrollY() {
var de = document.documentElement;
return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
}
/*确定浏览器视口的高度和宽度的两个函数*/
function windowHeight() {
var de = document.documentElement;
return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
}
function windowWidth() {
var de = document.documentElement;
return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment