导读:jquery获取浏览器的各种高度总结,现在才发现以前用js获取这些数据是多么的麻烦,jquery一句话就搞定了还把各浏览器的兼容性问题也给解决了
jquery获取浏览器的各种高度总结,现在才发现以前用js获取这些数据是多么的麻烦,jquery一句话就搞定了还把各浏览器的兼容性问题也给解决了。
alert($(window).height()); //浏览器时下窗口可视区域高度
alert($(document).height()); //浏览器时下窗口文档的高度
alert($(document.body).height());//浏览器时下窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin
alert($(window).width()); //浏览器时下窗口可视区域宽度
alert($(document).width());//浏览器时下窗口文档对于象宽度
alert($(document.body).width());//浏览器时下窗口文档body的高度
alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin
alert($(document).scrollTop()); //获取滚动条到顶部的垂直高度
alert($(document).scrollLeft()); //获取滚动条到左边的垂直宽度
本文转载自: PHP程序员笔记(http://www.phpernote.com/)
详细出处参考:http://www.phpernote.com/jquery/946.html