Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在构建一个动态图像滚动器,我需要知道如何调用元素相对于其第 n 个父元素的偏移位置。
有任何想法吗?
function getRelativePosition( element, nthparent_of_element ){ var posParent = $(nthparent_of_element).position(); var posElement = $(element).position(); return { top: posElement.top - posParent.top, left: posElement.left - posParent.left}; }