jQuery中的尺寸及位置的取和设

 1、offset();

获取位置值:

$(selector).offset().left;
$(selector).offset().top;

设置位置值:

$(selector).offset({top:100;left:100});

2、height();

获取元素的高度值:

$("selector").height();

设置元素的高度值:

$("selector").height(20);

3.width();

获取元素当前计算的宽度值:(不包括补白、边框和边距)

$("selector").width();

设置元素当前计算的宽度值:

$("selector").width(20);

4.innerHeight():

获取元素高度值:(包括补白、不边框和边距)

$("selector").innerHeight();

设置元素高度值:

$("selector").innerHeight(20);

5.innerWidth():

获取元素宽度值:(包括补白、不包括边框和边距)

$("selector").innerWidth();

设置元素高度值:

$("selector").innerWidth(20);

6.outerHeight(true):

获取元素高度值:(包括补白、边框;参数为true时,边距计算在内)

$("selector").outerHeight();

7.outerWidth([options]):

设置元素高度值:(包括补白、边框;参数为true时,边距计算在内)

$("selector").outerWidth();

 $(window).height(); //浏览器当前窗口可视区域高度
 $(document).height(); //浏览器当前窗口文档的高度 (个人认为是可视窗口的高度+滚动条高度)
 $(document.body).height();//浏览器当前窗口文档body的高度
 $(document.body).outerHeight(true);//浏览器当前窗口文档body的总高度 包括border padding margin;设置为true时,边距计算在内;默认为false;
 $(window).width(); //浏览器当前窗口可视区域宽度
 $(document).width();//浏览器当前窗口文档对象宽度
 $(document.body).width();//浏览器当前窗口文档body的高度
 $(document.body).outerWidth(true);//浏览器当前窗口文档body的总宽度 包括border padding margin;

原文地址:https://www.cnblogs.com/yzg1/p/4453778.html