我正在使用一个div ...
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) +
$(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) +
$(window).scrollLeft() + "px");
return this;
}
然后我想将另一个div移到这个居中的div的正上方,这样它们就会如下所示......
|-------------|
| Moved Above |
|-------------|
| |
| Centered |
| |
|-------------|
我将如何实现这一目标?
答案 0 :(得分:1)
您可以使用jQuery的prepend()或prependTo()函数将新内容置于当前。
答案 1 :(得分:0)
我会使用Offset:
var offs = $("#centered").offset();
$("#movedabove").css({
left: offs.left()+"px",
bottom: offs.top()+"px"
});
但我同意以前的答案更实际。