Skip to content

Commit 4077281

Browse files
hiikezoemoz-wptsync-bot
authored andcommitted
Round getBoundingClientRect()'s height and Element.scrollTop to avoid mis-comparison between double values and integer values.
The target element (top_box) height is defined by '60vh', the scroll position also depends on vh-units values, thus these values would be fractional on certain browser window sizes. (It can be observable with the default headless mode browser window size, 1366x768.) Differential Revision: https://phabricator.services.mozilla.com/D249193 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1966276 gecko-commit: 4fa6a18a08006b4fc3e852f5ee1faf912d709957 gecko-reviewers: emilio
1 parent ed43221 commit 4077281

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

css/css-scroll-snap/scroll-initial-target/scroll-initial-target-with-text-fragment-navigation-target.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@
5757
const expected_scroll_top = document.scrollingElement.scrollHeight -
5858
document.scrollingElement.clientHeight;
5959

60-
const scroll_start_target_top = top_box.getBoundingClientRect().height;
60+
const scroll_start_target_top = Math.round(top_box.getBoundingClientRect().height);
6161

62-
if (document.scrollingElement.scrollTop == scroll_start_target_top) {
62+
const actual_scroll_top = Math.round(document.scrollingElement.scrollTop);
63+
if (actual_scroll_top == scroll_start_target_top) {
6364
scroll_position = "AT_SCROLL_START_TARGET";
64-
} else if (document.scrollingElement.scrollTop == expected_scroll_top) {
65+
} else if (actual_scroll_top == expected_scroll_top) {
6566
scroll_position = "AT_TEXT_FRAGMENT";
6667
}
6768

0 commit comments

Comments
 (0)