Your absolute position properties are left
and top
.
(您的绝对位置属性为left
和top
。)
So, you will know what the smallest possible value is for top
and left
. (因此,您将知道top
和left
的最小可能值是多少。)
Define a topInitial
, leftInitial
, topOffset
and a leftOffset
variable which will contain the initial values and the difference between top
and left
of two subsequent elements to be displayed. (定义topInitial
, leftInitial
, topOffset
和leftOffset
变量,这些变量将包含初始值以及要显示的两个后续元素的top
和left
之间的差。)
Now, let's assume that you have a visibleElements
variable holding the elements to be displayed. (现在,假设您有一个visibleElements
变量,其中包含要显示的元素。)
In this case, you can use this algorithm: (在这种情况下,您可以使用以下算法:)
var currentTop = initialTop;
var currentLeft = initialLeft;
var current
for (var visibleElement of visibleElements) {
visibleElement.css('left', currentLeft + 'px').css('top', currentTop + 'px');
currentLeft += leftOffset;
currentTop += topOffset;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…