使用css3列-如何获得元素的位置

using css3 columns - how can get element position?

本文关键字:元素 位置 何获得 css3 使用      更新时间:2023-09-26

为了将长html文件与列分开,我使用了css3列。

padding: 0px
height: 1024px
-webkit-column-gap: 0px
-webkit-column-width: 768px

我想获得指定元素的位置,所以我使用了以下javascript代码:

function getPos(el) {
   for( var lx=0, ly=0; el!=null; lx+=el.offsetLeft, ly+=el.offsetTop, el=el.offsetParent);
         return {x:lx, y:ly};
}

我认为y值在0到height:1024px的范围内,但该值超过1024,x值在0到column-width:768的范围内。

我如何从左上角的第一个位置获得相对位置,y在0到1024之间,x是某个值?

对不起,我的英语很差。

谢谢。

jQuery方法position返回正确答案。有可能包括jQuery吗?