Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine dropdown should show upward or downward direction

I tried to design a dropdown component.

So far I faced an issue that the dropdown list is too long, so I keen to display it as the upward direction. I know Bootstrap has the same feature, but I want to do it my own. Any suggestions or keywords?

Thank you

UPDATE:

I don't use any library. Just refer the Bootstrap has achieved the purpose. These pictures are just examples downward

upward

like image 562
Raymond Yeh Avatar asked Sep 02 '25 03:09

Raymond Yeh


1 Answers

Here is what Bootstrap did, they were checking if the dropdown-menu height is less than the rest of the screen. Below is what I did.

let style = 'bottom';
let element = document.getElementById('myId');
if (window.innerHeight - element.getBoundingClientRect().bottom < element.scrollHeight){
     style = 'top'
}
like image 155
Kingsley Uchenna Avatar answered Sep 04 '25 17:09

Kingsley Uchenna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!