Mostrar desplegable hacia arriba y hacia abajo

let style = 'bottom';
let element = document.getElementById('myId');
if (window.innerHeight - element.getBoundingClientRect().bottom < element.scrollHeight){
     style = 'top'
}
KingUche