$elem
içinde yüklü. Daha iyi bir yaklaşımın jQuery'nin .offsetParent()
hesaplamasını kullanmasıdır, bu da fixed
ve absolute
pozisyonlarının ebeveynleri için bir araya gelecek, çünkü bunlar çocuğun pozisyonu üzerinde benzer bir etkiye sahip olacaktır.
söyleyen
, işte burada göreli pozisyon (see JSFiddle) var hesaplamak için .offsetParent()
kullanma hakkında gitmek nasıl hızlı bir mock-up var:
// Given a target, find it's first offset parent, and work out the targets position
// relative to the parent, by deducting their respective .offset() values
var $target = $("#bar"),
$offsetParent = $target.offsetParent(),
oTarget = $target.offset(),
oParent = $offsetParent.offset(),
posTop = oTarget.top - oParent.top,
posLeft = oTarget.left - oParent.left;
// Validate this works by cloning #bar and positioning the clone directly on top
// Result should be a blue "bar" rather than a "red" one.
$target.clone().appendTo($offsetParent).attr("id", "confirm").css({
top: posTop,
left: posLeft
});
Kesinlikle konumlandırma alt öğeleri için en iyi çözüm! –