Storing the IntersectionObserver result put shadows on tables that did not overflow

日本語

Contents of this article

Summary

For the tables in this site’s articles, three implementations that show a shadow on the side where horizontal scrolling has more content were compared. The one that produced no errors was the implementation that calculates from sentinel positions: it uses observation only as a trigger for calculation, and calculates whether there is more content by comparing the rectangles of the 1px sentinel elements at both ends with the rectangle visible within the container. This implementation treats rectangles that touch at an edge as visible, and aligns the boundary of the calculation with the observer’s judgment.

With the implementation that stores the observation results in left and right variables, the implementation that keeps observation results as state, opening a closed dialog 60 times showed a shadow on tables that did not overflow 13 times in WebKit 26.0 and 0 times in Chromium. With the implementation that calculates from scrollLeft, out of 10 returns to the left edge, the left shadow remained 9 times in Chromium and 2 times in WebKit 26.0. With the implementation that calculates from sentinel positions, it was 0 times in both checks.

This implementation assumes that the container wrapping the table has no border, no padding, and no vertical scrollbar. The checks were done over one day in Chromium 149 and WebKit 26.0. How it looks in Safari on an iPhone, and how a screen reader reads it, have not been tried.

What you can take away

Developers who show horizontal scroll shadows with IntersectionObserver can learn the following from this article.

This article rests on the commit records, code, tests, and check records from one day of developing this site, and on specifications and published documents.