jQuery 获取屏幕高度、宽度

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

源引:http://www.cnblogs.com/hoojo/archive/2012/02/16/2354663.html

发表评论

表情:
评论列表 (有 0 条评论,363人围观)

还没有评论,来说两句吧...

相关阅读