I am currently working with an HTML element that is displayed when a button is clicked, similar to a popup. My goal is to determine if the element is within the browser's viewport and then position it accordingly inside the viewport. Is there a proper method to accomplish this task?
My current approach involves checking the height of the viewport and comparing it to the position where the element will be attached. I have been using the following code snippet for this purpose:
If(window.innerHeight > yPointWhereElementIsAttachedTo + heightOfElement) //attach element;
However, I am curious to know if there is a more optimal way to achieve this.