5 examples of 'offset .top' in JavaScript

Every line of 'offset .top' 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
this disclaimer
19function getOffsetTop(rect, vertical) {
20 let offset = 0;
21
22 if (typeof vertical === 'number') {
23 offset = vertical;
24 } else if (vertical === 'center') {
25 offset = rect.height / 2;
26 } else if (vertical === 'bottom') {
27 offset = rect.height;
28 }
29
30 return offset;
31}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

169getTopPositonY() {
170 const item = this.getTopItem();
171
172 return item ? item.position.y : 0;
173}
14function getOffsetTop(element: HTMLElement, container: AnchorContainer): number {
15 if (!element) {
16 return 0;
17 }
18
19 if (!element.getClientRects().length) {
20 return 0;
21 }
22
23 const rect = element.getBoundingClientRect();
24
25 if (rect.width || rect.height) {
26 if (container === window) {
27 container = element.ownerDocument.documentElement;
28 return rect.top - container.clientTop;
29 }
30 return rect.top - (container as HTMLElement).getBoundingClientRect().top;
31 }
32
33 return rect.top;
34}
207function getElementTop(element){
208 var actualTop = element.offsetTop;
209 var current = element.offsetParent;
210 while (current !== null){
211 actualTop += current.offsetTop;
212 current = current.offsetParent;
213 }
214 return actualTop;
215}
31function bottomPos(element) {
32 return element.offset().top + element.outerHeight();
33}

Related snippets