1. 做手机Web开发做浏览器兼容用到了,所以在网上找了些汇总下。
    2. alert($(window).height()); //浏览器当前窗口可视区域高度
    3. alert($(document).height()); //浏览器当前窗口文档的高度
    4. alert($(document.body).height());//浏览器当前窗口文档body的高度
    5. alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin
    6. alert($(window).width()); //浏览器当前窗口可视区域宽度
    7. alert($(document).width());//浏览器当前窗口文档对象宽度
    8. alert($(document.body).width());//浏览器当前窗口文档body的高度
    9. alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin
    10. // 获取页面的高度、宽度
    11. function getPageSize() {
    12. var xScroll, yScroll;
    13. if (window.innerHeight && window.scrollMaxY) {
    14. xScroll = window.innerWidth + window.scrollMaxX;
    15. yScroll = window.innerHeight + window.scrollMaxY;
    16. } else {
    17. if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
    18. xScroll = document.body.scrollWidth;
    19. yScroll = document.body.scrollHeight;
    20. } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    21. xScroll = document.body.offsetWidth;
    22. yScroll = document.body.offsetHeight;
    23. }
    24. }
    25. var windowWidth, windowHeight;
    26. if (self.innerHeight) { // all except Explorer
    27. if (document.documentElement.clientWidth) {
    28. windowWidth = document.documentElement.clientWidth;
    29. } else {
    30. windowWidth = self.innerWidth;
    31. }
    32. windowHeight = self.innerHeight;
    33. } else {
    34. if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    35. windowWidth = document.documentElement.clientWidth;
    36. windowHeight = document.documentElement.clientHeight;
    37. } else {
    38. if (document.body) { // other Explorers
    39. windowWidth = document.body.clientWidth;
    40. windowHeight = document.body.clientHeight;
    41. }
    42. }
    43. }
    44. // for small pages with total height less then height of the viewport
    45. if (yScroll < windowHeight) {
    46. pageHeight = windowHeight;
    47. } else {
    48. pageHeight = yScroll;
    49. }
    50. // for small pages with total width less then width of the viewport
    51. if (xScroll < windowWidth) {
    52. pageWidth = xScroll;
    53. } else {
    54. pageWidth = windowWidth;
    55. }
    56. arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    57. return arrayPageSize;
    58. }
    59. // 滚动条
    60. document.body.scrollTop;
    61. $(document).scrollTop();