How can I determine the distance of the element from the bottom of the visual area?

I want to press the up and down keys to achieve the selection function, but if the selected element reaches the bottom of the visual area, pressing the key again requires the page to scroll down, but how to judge the distance between the top or bottom of the visible area in the element?
Thank you!

May.05,2022

if the height of each row is fixed, change the scrollTop of the scroll bar.

idea 1:
scrollTop = index * height of each row (this makes the selected data always in the first place)

idea 2: to determine whether the element is invisible or not, we need to adjust the height of the scroll bar
downward invisible: (index+1) * height-popHeight (drop-down box height) > scrollTop
upward invisible: index * height < scrollTop


function checkShow(ele) { // jq
    var scrollTop = $(window).scrollTop();  //
    var windowHeight = $(window).height(); // 
    var offsetTop = ele.offset().top;  //document

    if (offsetTop < (scrollTop + windowHeight) && offsetTop > scrollTop) { //2
        return true;
    }
    return false;
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eba621-69f3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eba621-69f3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?