本文整理匯總了TypeScript中@ephox/dom-globals.HTMLElement.getBoundingClientRect方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript HTMLElement.getBoundingClientRect方法的具體用法?TypeScript HTMLElement.getBoundingClientRect怎麽用?TypeScript HTMLElement.getBoundingClientRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/dom-globals.HTMLElement
的用法示例。
在下文中一共展示了HTMLElement.getBoundingClientRect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
const getAbsoluteClientRect = (root: HTMLElement, element: HTMLElement, before: boolean): ClientRect => {
const clientRect = GeomClientRect.collapse(element.getBoundingClientRect(), before);
let docElm, scrollX, scrollY, margin, rootRect;
if (root.tagName === 'BODY') {
docElm = root.ownerDocument.documentElement;
scrollX = root.scrollLeft || docElm.scrollLeft;
scrollY = root.scrollTop || docElm.scrollTop;
} else {
rootRect = root.getBoundingClientRect();
scrollX = root.scrollLeft - rootRect.left;
scrollY = root.scrollTop - rootRect.top;
}
clientRect.left += scrollX;
clientRect.right += scrollX;
clientRect.top += scrollY;
clientRect.bottom += scrollY;
clientRect.width = 1;
margin = element.offsetWidth - element.clientWidth;
if (margin > 0) {
if (before) {
margin *= -1;
}
clientRect.left += margin;
clientRect.right += margin;
}
return clientRect;
};
示例2: function
const measureElement = function (elm: HTMLElement) {
const clientRect = elm.getBoundingClientRect();
return toAbsolute({
x: clientRect.left,
y: clientRect.top,
w: Math.max(elm.clientWidth, elm.offsetWidth),
h: Math.max(elm.clientHeight, elm.offsetHeight)
});
};