按其视觉顺序接收元素列表 [英] Receive list of elements in their visual order

查看:121
本文介绍了按其视觉顺序接收元素列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的网格(div容器):

I have a grid (div container) which looks like this:

但是,div#2可能位于div#1上,依此类推.这是通过CSS位置完成的,因此它们的DOM顺序将相同. 我想确定他们的视觉顺序.是否有jQuery selector或其他方法可以做到这一点?

However it's possible that div #2 can be on the place of div #1 and so on. This is done via CSS position, so their DOM order will be the same. I want to determine their visual order. Is there a jQuery selector or some other way to do this?

//解决方案添加为答案

推荐答案

使用$(elem).position()获取每个div的屏幕坐标.通过查看topleft属性,您可以推断视觉顺序.

Use $(elem).position() to get screen coordinates for each div. By looking at the top and left properties you can infer a visual ordering.

这篇关于按其视觉顺序接收元素列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆