MCPcopy Create free account
hub / github.com/angular/components / getOffset

Function getOffset

src/cdk/scrolling/virtual-for-of.ts:63–75  ·  view source on GitHub ↗

Helper to extract the offset of a DOM Node in a certain direction.

(orientation: 'horizontal' | 'vertical', direction: 'start' | 'end', node: Node)

Source from the content-addressed store, hash-verified

61
62/** Helper to extract the offset of a DOM Node in a certain direction. */
63function getOffset(orientation: 'horizontal' | 'vertical', direction: 'start' | 'end', node: Node) {
64 const el = node as Element;
65 if (!el.getBoundingClientRect) {
66 return 0;
67 }
68 const rect = el.getBoundingClientRect();
69
70 if (orientation === 'horizontal') {
71 return direction === 'start' ? rect.left : rect.right;
72 }
73
74 return direction === 'start' ? rect.top : rect.bottom;
75}
76
77/**
78 * A directive similar to `ngForOf` to be used for rendering data inside a virtual scrolling

Callers 1

measureRangeSizeMethod · 0.85

Calls 1

getBoundingClientRectMethod · 0.80

Tested by

no test coverage detected