首页 > Web开发 > 详细

jQuery的相关尺寸获取 - 学习笔记

时间:2020-01-29 22:46:42      阅读:86      评论:0      收藏:0      [点我收藏+]

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

 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);

jQuery的相关尺寸获取 - 学习笔记

原文:https://www.cnblogs.com/aduner/p/12238428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!