jQuery的相关尺寸获取

获取元素相对于文档的偏移量

 var pos = $('#small').offset(); 
 console.log(pos.left);
 console.log(pos.top);

获取当前元素相对于父级元素的偏移量

 var l = $('#small').position().left;
 var t = $('#small').position().top;
 console.log(l,t);

获取文档滚动距离

 var st = $(document).scrollTop();
 var sl = $(document).scrollLeft();

获取元素的宽度和高度

 var w = $('#big').width();
 var h = $('#big').height();

设置元素的宽度和高度

 $('#big').width(400);
 $('#big').height(400);
 // console.log(w,h);

获取可视区域的宽度和高度

 var w = $(window).width();
 var h = $(window).height();

获取文档的宽度和高度

 var w = $(document).width();
 var h = $(document).height();
 console.log(w,h);
原文地址:https://www.cnblogs.com/aduner/p/12238428.html