Skip to content

Commit ea1f366

Browse files
committed
The top's arrival test cannot be a zero-tolerance comparison
Reported in review, and it holds: at the top of the ledger the arrow pointed up and a second press moved the page by zero pixels. The landing and the test for it read one number, and the browser does not keep it. The offset is answered in 1/64px by getBoundingClientRect(); scrollTo() lands on a whole pixel, rounded to nearest. Landing at 503.7656 therefore puts the reader at 504, and a strict 「greater than 503.7656」 reads that as 「there is more above」. Measured across viewport widths the gap never reached half a pixel — and it decided the outcome. The same code froze the control at 1300, 1440, 1100 and 760, and behaved at 897, because 897's offset lands on a fraction below the nearest integer rather than above it. A defect that only some widths produce is harder to recognise as one than a defect that always happens. Rounding the offset up is what 「arrived」 means, rather than a tolerance chosen to cover the measurement. Rounding down fails the moment the browser rounds up; rounding to nearest is right only for the rule in force today, and nothing in a green run would say otherwise. Up holds for all three. The bottom end is deliberately left alone. Its landing is the end at the top of the viewport while its test asks whether the end is still below the fold — a whole viewport apart, so no rounding error reaches across it — and its offset happened to be a whole number at every width tried. That is why the two ends are treated differently rather than symmetrically.
1 parent f8de63d commit ea1f366

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • plugins/avatasia/mmc-trajectory/miniapp/client

‎plugins/avatasia/mmc-trajectory/miniapp/client/index.html‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6537,7 +6537,19 @@ <h2 class="section-title" id="inspector-heading">检视</h2>
65376537
*/
65386538
function ledgerJumpGoesUp() {
65396539
var y = window.scrollY || window.pageYOffset || 0;
6540-
var canUp = y > ledgerTopOffset();
6540+
// The landing point and this test read one number, and the browser does not keep it:
6541+
// getBoundingClientRect() answers in 1/64px while scrollTo() lands on a whole pixel, so the
6542+
// landing sits within half a pixel either side of what the offset says. A zero-tolerance
6543+
// 「strictly greater」 then reads the landing itself as 「there is more above」 — at the top of
6544+
// the ledger the arrow points up and pressing it again moves nothing at all.
6545+
//
6546+
// Rounding the offset up is what 「arrived」 means; a tolerance chosen to cover the
6547+
// measurement would instead have to be right about the rounding, which is the browser's
6548+
// business. Every landing is at or below the rounded-up offset whichever way it rounded,
6549+
// so the two agree on floor, on nearest, and on ceiling alike. Measured across viewport
6550+
// widths the gap never reached half a pixel, and it decided the outcome: the same code
6551+
// landed correctly at one width and froze the control at another.
6552+
var canUp = y > Math.ceil(ledgerTopOffset());
65416553
var canDown = ledgerEndBelow();
65426554
if (!canUp && !canDown) return false; // the whole ledger is on screen: nothing to jump to
65436555
if (!canDown) return true; // the end is reached or gone past: up is all that is left

0 commit comments

Comments
 (0)