Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix jittery scrolling #40215

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions doc/api_assets/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
let eqIsh = (a, b, fuzz = 2) => {
return (Math.abs(a - b) <= fuzz);
};

let rectNotEQ = (a, b) => {
return (!eqIsh(a.width, b.width) ||
!eqIsh(a.height, b.height));
};

let spaced = new WeakMap();

let reserveSpace = (el, rect = el.getClientBoundingRect()) => {
let old = spaced.get(el);
if (!old || rectNotEQ(old, rect)) {
spaced.set(el, rect);
el.attributeStyleMap.set(
"contain-intrinsic-size",
`${rect.width}px ${rect.height}px`
);
}
};

let iObs = new IntersectionObserver(
(entries, o) => {
entries.forEach((entry) => {

reserveSpace(entry.target,
entry.boundingClientRect);
});
},
{ rootMargin: "500px 0px 500px 0px" }
);

let rObs = new ResizeObserver(
(entries, o) => {
entries.forEach((entry) => {
reserveSpace(entry.target, entry.contentRect);
});
}
);

let articles =
document.querySelectorAll("#apicontent>section");

articles.forEach((el) => {
iObs.observe(el);
rObs.observe(el);
});

requestAnimationFrame(() => {
requestAnimationFrame(() => {
articles[0].attributeStyleMap.set(
"content-visibility",
"auto"
);
});
});
4 changes: 3 additions & 1 deletion doc/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/hljs.css">
<link rel="canonical" href="https://nodejs.org/api/__FILENAME__.html">
<script src="assets/script.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add to the existing script?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduh95 asked to move it to a different file

maybe you can put this to a separate .js file in doc/api_assets so the linter can autofix that for you.

saltybuckets marked this conversation as resolved.
Show resolved Hide resolved
</head>
<body class="alt apidoc" id="api-section-__FILENAME__">
<div id="content" class="clearfix">
Expand Down Expand Up @@ -98,6 +99,7 @@ <h1>Node.js __VERSION__ documentation</h1>
});
}
}

saltybuckets marked this conversation as resolved.
Show resolved Hide resolved
</script>
</body>
</html>
</html>
saltybuckets marked this conversation as resolved.
Show resolved Hide resolved