Say we have a long list, so some items may not be seen at the beginning.
After user scrolls the screen, some more items are seen.
<ul>
<li>
<li>
<li>
--------not seen at the beginning-------
<li>
<li>
<li>
....
</ul>
What is the best practice for judging which item is seen by the user?
Maybe known as Impression, but I couldn't find anything about it.
On any HTML element, you can get its position on the screen using
getBoundingClientRect():The result is an object with the properites
top,right,bottom,left,widthandheight.You should also check the window height:
Now, you can compare the
topandbottomvalues of the element's bounding rect with the window height to determine if it's visible:You may also want to check the percentage of the element that is shown (depends on when you decide to start counting impressions: full view or partial view as well).