1

做完之后

$view.offset({
   left : X, //X is the same each time
   top : this.y
});
console.log($view.offset()); //outputs what it should

对于几个对象。我看到(在萤火虫中)以下html代码

<div id="4017" class="text-block" style="position: relative; top: 2px; left: 22px;">
<div id="4043" class="text-block" style="position: relative; top: 41px; left: -64px;">
<div id="4053" class="text-block" style="position: relative; top: 80px; left: -95px;">
<div id="4081" class="text-block" style="position: relative; top: 119px; left: -135px;">

left对于所有 div 应该是相同的(并且它被显示,所以 ifleft对于 each 是相等的div)。尽管显示了,但为什么left每个 div 都不相同,所以所有 div 都相同?divleft

在 CSS 中,我有:

div.text-block {
   display: inline-block;
}

先感谢您!

UPD: div 位于其他三个 div 旁边:

<div id="app-container">
    <div id="canvas-container">
        <div id="canvas">
            <!-- divs are located here -->
        </div>
     </div>
</div>

在相应的 CSS 中,我有:

#canvas {
  position: absolute;
  background-color: white;
  width: 100%;
  height: 100%;
}

#app-container {
  height: auto !important;
  min-height: 100%;
}

#canvas-container {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
4

1 回答 1

1

正如jQuery 文档中所说,

.offset(坐标)

描述:设置匹配元素集中每个元素的当前坐标,相对于文档。

因此,如果您的元素位于相对于文档未位于位置 (0, 0) 的其他元素中,则会应用偏移量。


编辑

具有相同左值的相对定位的内联元素:

演示图片

于 2012-11-22T13:35:32.220 回答