में लोड मुझे लगता है कि आप यह पहली रिश्तेदार माता पिता है से बच्चे की स्थिति की गणना करने के लिए इस जानना चाहता हूँ चाहते हैं। मैं सुझाव दूंगा कि बेहतर दृष्टिकोण केवल jQuery की .offsetParent()
गणना का उपयोग करना होगा, जो fixed
और absolute
की स्थिति के माता-पिता की भी तलाश करेगा, क्योंकि इससे बच्चे की स्थिति पर भी असर पड़ेगा।
जिसके अनुसार, यहां .offsetParent()
का उपयोग कर इसे रिश्तेदार की स्थिति (see JSFiddle) है की गणना करने के बारे में आप कैसे जा सकते हैं की एक त्वरित नकली है:
// 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
});
स्रोत
2014-03-28 11:48:32
बिल्कुल पोजीशनिंग बच्चे तत्वों के लिए सबसे अच्छा समाधान! –