Hi I have a list of Li elements with overflow hidden, I just want to find the last visible Li on screen let say a element which is closest to right
Loading
Hi I have a list of Li elements with overflow hidden, I just want to find the last visible Li on screen let say a element which is closest to right
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Uday DodiyaPosted Jan 10, 2023, 4:17 AM
Another Solution
Here's one way you could do this using JavaScript:
Get the
lielements that are visible on the screen by using thegetClientRectsmethod on each element. This method returns a list of rectangles that represent the element's size and position relative to the viewport.Iterate through the list of visible
lielements and find the one that is closest to the right edge of the viewport. You can do this by comparing therightproperty of each element's rectangle to the width of the viewport. The element with the highestrightvalue is the one that is closest to the right edge.Here's some example code that demonstrates how this could work:
This code will find the last visible
lielement by iterating through all of thelielements and keeping track of the one with the highestrightvalue.Uday DodiyaPosted Jan 10, 2023, 4:14 AM
Answer By ChatGPT
You can use JavaScript to determine the visibility of each
lielement and then find the one that is closest to the right edge of the screen. Here's an example of how you might do this:This code iterates through all of the
lielements, checks to see if they are visible on the screen (based on their bounding rectangle), and then finds the one that is closest to the right edge of the screen.