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.
- You learn how to use observation only as a trigger for calculation, and to calculate whether there is more content with the same boundary as the observer’s judgment.
- You learn the mechanism by which, in the implementation that keeps observation results as state, a shadow appeared right after a closed
dialogwas opened. - You learn the mechanism by which, in the implementation that calculates from
scrollLeft, the left shadow remained after returning to the left edge. - You learn the assumptions under which the implementation that calculates from sentinel positions holds.
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.
The rest of this article is paid
This is a subscriber-only article, available to subscribers.
The paid part is about 15,300 characters, roughly a 31-minute read.
Read every paid article
Standard is 490 JPY / month
Four new paid articles ship every month. For yearly billing and the full comparison, see the plans.
Add dialogue and columns
Premium is 980 JPY / month
Premium adds the subscriber-only columns and dialogue with matsumotory-kun on top of every paid article. See the plans for details.
Prices include tax. Purchases and subscriptions start after you sign in. Subscribers and readers who already bought this article can sign in and read the full article; for the plans, see the plans page.
Sales are available in supported regions only; the Terms list where we sell. All charges are in Japanese yen.