确定列表元素作为内联块的列数或行数一个部门的怪癖
第一个问题。希望这不是重演。
我有一个无序列表的缩略图显示为内联块。这些图像全部排列在一个漂亮、干净的网格中。但是,根据包装器的大小,列数和行数可能会有所不同。我的数据会在悬停时在图像上弹出(有延迟)。数据显示在缩略图的下方和右侧。但这意味着如果图像位于最右侧,数据可能会显示在页面之外。 我想知道是否有一种方法可以通过 jquery 确定行号或列号,这样我就可以使两端的元素正确显示详细信息。
如果没有,我想我可以获取列表元素的外部宽度及其边距和包装器的内部宽度。我将包装器除以列表元素,然后得到每行列表元素的最大数量!然后我可以通过 JavaScript 魔法的各种方式找到行边缘的元素。然而,这并不总是有效。
例如,我之前的测试有 150 像素的方形缩略图,边距为 2 像素。包装纸的内部宽度为 937. 937 / 154 = 6.0844。顺便说一句,这些数字是直接从 jquery 中得出的。然而,行是用 5 列呈现的。将边距降至 1,使宽度为 152 像素,这样我就可以每行获得 6 个图像 (6.164)。我完全可以为我的目标开发一个插件,但这个小怪癖困扰着我。
有什么想法或建议吗?
顺便说一句,这已经在 Chrome 和 Firefox 中进行了测试。
First question. Hope this isn't a repeat.
I have an unordered list of thumbnails displayed as inline-blocks. The images all line up in a nice, clean grid. But, depending on the size of their wrapper, the number of columns and rows can vary. I have data that will pop up over the image on hover (with a delay). The data is displayed below and to the right of the thumbnail. But this means the data can show up off the page if the image is on the far right.
I was wondering if there is a way of determining the row or column number via jquery, so I could make elements at either end display the details properly.
If there isn't, I was thinking that I could get the outer width of my list elements with their margin and the inner width of the wrapper. I'd divide the wrapper by the list element, and I would then get the maximum number of list elements per row! Then I could find elements on the edge of a row through various means of javascript magic. However, this does not always work.
For instance, my previous test had 150px square thumbnails with a 2px margin. The interior width of the wrapper was 937. 937 / 154 = 6.0844. Those are numbers straight out of jquery, by the way. However, the rows were rendered with 5 columns. Dropping my margin to 1 so that my widths were 152px allowed me to get 6 images per row (6.164). I could very well work on a plugin for my goal as it is, but this little quirk bothered me.
Any ideas or recommendations?
By the way, this was tested in Chrome and Firefox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想如果没有至少 50 名代表我就无法发表评论......所以我就在这里发帖。
正如 +Kevin B 所说,并且我同意他的观点,一种可能的解决方案是找到作为弹出窗口父级的 obj 的位置。将该位置与页面的宽度进行比较,如果它小于弹出窗口的宽度,则将弹出窗口进一步向左移动以进行补偿。例子:
I guess I can't comment without at least 50 rep... So I'll just post here.
As +Kevin B said, and who i agree with, one possible solution is to find the position of the obj that is the parent for the popup. Compare that position to the width of the page and if it's smaller than the width of your popup move the popup further to the left to compensate. Example: