1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 1× 14× 14× 14× 14× 14× 14× | export function bringInView(parent, child) { let menu = document.querySelector(parent); let item = document.querySelector(child); // Ensure the elements still exist Iif (!menu || !item) { return; } let menuRect = menu.getBoundingClientRect(); let itemRect = item.getBoundingClientRect(); Iif (itemRect.bottom > menuRect.bottom || itemRect.top < menuRect.top) { menu.scrollTop = item.offsetTop + item.clientHeight - menu.offsetHeight; } } |