浏览器窗口的问题

来源:互联网 发布:matlab随机森林算法 编辑:程序博客网 时间:2024/06/05 17:04

// 浏览器窗口可视区域大小(不包括工具栏和滚动条等边线)
js写法:

var client_w = document.documentElement.clientWidth || document.body.clientWidth;var client_h = document.documentElement.clientHeight || document.body.clientHeight;
var offset_w = document.documentElement.offsetWidth || document.body.offsetWidth;var offset_h = document.documentElement.offsetHeight || document.body.offsetHeight;

// 网页内容实际宽高(包括工具栏和滚动条等边线)

var scroll_w = document.documentElement.scrollWidth || document.body.scrollWidth;var scroll_h = document.documentElement.scrollHeight || document.body.scrollHeight;

// 滚动的高度

var scroll_Top = document.documentElement.scrollTop||document.body.scrollTop;

以上都记录的是js方法:下面说说jq方法:

Position()方法返回的是元素距离父元素顶部的距离Offset()方法返回的是元素距离文档顶部的距离$(o).position().left = style.left,        $(o).position().top = style.top;$(o).offset().top元素距离文档顶的距离,$(o).offset().left元素距离文档左边缘的距离
**3)获取元素的尺寸:左边jquery方法,右边原生方法**    $(o).width() = o.style.width;     $(o).innerWidth() = o.style.width+o.style.padding;    $(o).outerWidth() = o.offsetWidth = o.style.width+o.style.padding+o.style.border;    $(o).outerWidth(true) = o.style.width+o.style.padding+o.style.border+o.style.margin;