下面是我爱模板网总结的,javascript 和 jQuery 获取浏览器各种宽度和高度的方法大全:
JavaScript:
01 | alert(document.body.clientWidth); |
02 | alert(document.body.clientHeight); |
03 | alert(document.body.offsetWidth); |
04 | alert(document.body.offsetHeight); |
05 | alert(document.body.scrollWidth); |
06 | alert(document.body.scrollHeight); |
07 | alert(document.body.scrollTop); |
08 | alert(document.body.scrollLeft); |
09 | alert(window.screenTop); |
10 | alert(window.screenLeft); |
11 | alert(window.screen.height); |
12 | alert(window.screen.width); |
13 | alert(window.screen.availHeight); |
14 | alert(window.screen.availWidth); |
jQuery
1 | alert($(window).height()); |
2 | alert($(document).height()); |
3 | alert($(document.body).height()); |
4 | alert($(document.body).outerHeight( true )); |
5 | alert($(window).width()); |
6 | alert($(document).width()); |
7 | alert($(document.body).width()); |
8 | alert($(document.body).outerWidth( true )); |