UNPKG

@ebay/ebayui-core

Version:

Collection of core eBay components; considered to be the building blocks for all composite structures, pages & apps.

21 lines (20 loc) 618 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scroll = scroll; /** * Scrolls the parent element until the child element is in view */ function scroll(el) { if (!el) { return; } const parentEl = el && el.parentElement; const offsetBottom = el.offsetTop + el.offsetHeight; const scrollBottom = parentEl.scrollTop + parentEl.offsetHeight; if (el.offsetTop < parentEl.scrollTop) { parentEl.scrollTop = el.offsetTop; } else if (offsetBottom > scrollBottom) { parentEl.scrollTop = offsetBottom - parentEl.offsetHeight; } }