在jQuery中轻松地将元素放在另一个元素上?

Mar*_*ine 6 jquery element

我需要使用jQuery在图像上定位div.我可以使用使用position: fixed并使用top和left来创建它,使用元素偏移来定位它,但它很糟糕,因为如果用户滚动,元素将不会在元素的顶部.

还有其他想法吗?

Nic*_*ver 10

如果您正在执行此多个位置,则可以执行以下操作:

<div style="position: relative;">
  <div style="position:absolute; width: 276px; height: 110px; z-index: 2;">
    Content here will be on top the image
  </div>
  <img style="width: 276px; height: 110px;" src='http://www.google.com/intl/en_ALL/images/logo.gif' alt="Test Img" />
</div>??????????????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

如果匹配height/ width在内部/ div的欧尔样式属性,内部<div>自带<img />,你给内<div>较高的Z-指数比图像,它会完全重叠的图像.

你可以在这里看到一个这样的例子:http://jsfiddle.net/ZcBus/