简体   繁体   English

使用css3列 - 如何获取元素位置?

[英]using css3 columns - how can get element position?

To divide the long html file with the columns, I used css3 columns. 要将长html文件与列分开,我使用了css3列。

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

And i wanted to get the position of the specified element, so i used the following javascript code. 我想获得指定元素的位置,所以我使用了以下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};
}

I thought that the y value is in range of 0 to height:1024px, but that value exceeds 1024 and x value is in range of 0 to column-width:768. 我认为y值的范围是0到高度:1024px,但是该值超过1024,x值的范围是0到列宽:768。

How can i get the realative position from the first top left position which y is in 0 to 1024 and x is some value? 如何从第一个左上角位置获得realative位置,y在0到1024之间,x是某个值?

I'm sorry for my poor english. 对不起,我的英语很差。

Thanks. 谢谢。

The jQuery method position returns the correct answer for this. jQuery方法position为此返回正确的答案。 Is it possible for you to include jQuery? 你有可能包含jQuery吗?

See http://jsfiddle.net/chris5marsh/GM2kp/ for an example. 有关示例,请参见http://jsfiddle.net/chris5marsh/GM2kp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM