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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ test/message/esm_display_syntax_error.mjs
tools/icu
tools/lint-md/lint-md.mjs
benchmark/tmp
doc/**/*.js
!.eslintrc.js
59 changes: 59 additions & 0 deletions doc/api_assets/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const eqIsh = (a, b, fuzz = 2) => {
saltybuckets marked this conversation as resolved.
Show resolved Hide resolved
return (Math.abs(a - b) <= fuzz);
};

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

const spaced = new WeakMap();

const reserveSpace = (el, rect = el.getClientBoundingRect()) => {
const 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`
);
}
};

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

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

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

const articles =
document.querySelectorAll('#apicontent>section');

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

requestAnimationFrame(() => {
requestAnimationFrame(() => {
articles[0].attributeStyleMap.set(
'content-visibility',
'auto'
);
});
});
saltybuckets marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions 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