10 examples of 'getboundingclientrect jquery' in JavaScript

Every line of 'getboundingclientrect jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
231getBoundingClientRect(el) {
232 try {
233 return el.getBoundingClientRect();
234 }
235 catch (e) {
236 return { top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0 };
237 }
238}
22function getRect(element) {
23 return element.getBoundingClientRect();
24}
666function getRect(element) {
667 return element[0].getBoundingClientRect();
668}
5function getBoundingRect(selector: string): DOMRect | null {
6 const element = document.querySelector(selector);
7
8 if (!element) {
9 return null;
10 }
11
12 return element.getBoundingClientRect() as DOMRect;
13}
1export function offset(element: HTMLElement) {
2 // Support: IE <=11 only
3 // Running getBoundingClientRect on a
4 // disconnected node in IE throws an error
5 if (!element || !element.getClientRects().length) {
6 return {top: 0, left: 0};
7 }
8
9 let docElem: HTMLElement, rect: ClientRect, doc: Document;
10
11 rect = element.getBoundingClientRect();
12
13 // Make sure element is not hidden (display: none)
14 if (rect.width || rect.height) {
15 doc = element.ownerDocument;
16 docElem = doc.documentElement;
17
18 return {
19 top: rect.top + window.pageYOffset - docElem.clientTop,
20 left: rect.left + window.pageXOffset - docElem.clientLeft
21 };
22 }
23
24 // Return zeros for disconnected and hidden elements (gh-2310)
25 return rect;
26}
7function getClientBoundingBox(selector) {
8 return [document.querySelector(selector).getBoundingClientRect(),
9 window.devicePixelRatio];
10}
1016function getBoundingClientRectCompat ( elem ) {
1017 var elemRect = elem.getBoundingClientRect();
1018
1019 if ( elemRect.width === undefined || elemRect.height === undefined ) {
1020 // Fix for IE8
1021 elemRect = {
1022 top: elemRect.top,
1023 left: elemRect.left,
1024 bottom: elemRect.bottom,
1025 right: elemRect.right,
1026 width: elemRect.right - elemRect.left,
1027 height: elemRect.bottom - elemRect.top
1028 };
1029 }
1030
1031 return elemRect;
1032}
10export function getRect(node) {
11 return node !== window
12 ? node.getBoundingClientRect()
13 : { top: 0, left: 0, bottom: 0 };
14}
65function getTargetRect(target) {
66 return target !== window ? target.getBoundingClientRect() : {
67 top: 0,
68 left: 0,
69 bottom: 0
70 };
71} //获取target的滚动距离
8export function getOffsetRect(elem: HTMLElement): OffsetRectInterface {
9 const box = elem.getBoundingClientRect();
10 const body = document.body;
11 const doc = document.documentElement;
12 const scrollTop = window.pageYOffset || doc.scrollTop || body.scrollTop;
13 const scrollLeft = window.pageXOffset || doc.scrollLeft || body.scrollLeft;
14 const clientTop = doc.clientTop || body.clientTop || 0;
15 const clientLeft = doc.clientLeft || body.clientLeft || 0;
16
17 return {
18 top: Math.round(box.top + scrollTop - clientTop),
19 left: Math.round(box.left + scrollLeft - clientLeft),
20 width: elem.offsetWidth,
21 height: elem.offsetHeight
22 };
23}

Related snippets