providers: 添加供应商 scrolls down to the sheet on the first click, and the sheet unrolls with the view going down along with it (第一次点击添加供应商…并不会自动向下滚动,第二次才会;滚动跟展开都没有丝滑的动画) — the view's guard against scrolls nobody asked for (backToReader) put back the smooth scrollIntoView the button started, as it never said scrollOnPurpose; it only got through when something else happened to have. Now the button says so, and the sheet opens from nothing to its height on the rows' spring (ROW_OPEN), its head and tiles easing down into place, while the view's scrollTop is set frame by frame from the sheet's height: from when the sheet reaches the view's foot to when it is whole, into room the sheet has made, so it neither jumps nor stops short, until the sheet's top is 12px under the view's — scrollTop set directly, which WebKit animates where a smooth scrollIntoView may not. Scrolling meanwhile hands the view back to the reader. 关闭 rolls it up the other way before it is hidden. Reduced motion jumps there as before. Checked in a sandbox HOME with six providers in headless Chrome: on the first click scrollTop went 0 → 301 over ~550 ms along with the height (0 → 868), no jump; closed and reopened the same; reduced motion lands at 301 with no animation

This commit is contained in:
yetone
2026-09-29 01:38:40 +08:00
parent 7353323382
commit 92aef441d4
+59 -4
View File
@@ -2102,7 +2102,7 @@ function renderAdd() {
head.append(imp);
if (providers.providers.length) {
const x = el("button", "text", t("Close"));
x.onclick = () => { adding = false; editing = null; draft = null; presetQuery = ""; renderProviders(); };
x.onclick = () => rollUpSheet(sheet, () => { adding = false; editing = null; draft = null; presetQuery = ""; renderProviders(); });
head.append(x);
}
sheet.append(head);
@@ -4247,13 +4247,68 @@ function editorError(msg, kind = "err") {
function slug(s) { return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""); }
function hostOf(u) { try { return new URL(u.includes("://") ? u : "https://" + u).host; } catch { return ""; } }
// the sheet opens below the list: the view goes down to its top with it
// the sheet opens below the list: it unrolls on the rows' spring and the
// view goes down with it
$("#addProvider").onclick = () => {
adding = true; editing = null; draft = null; renderProviders();
const smooth = !matchMedia("(prefers-reduced-motion: reduce)").matches;
requestAnimationFrame(() => $("#addSheet").scrollIntoView({ behavior: smooth ? "smooth" : "auto", block: "start" }));
unrollSheet($("#view-providers"), $("#addSheet"));
};
// unrollSheet opens a sheet just drawn at the foot of a view from nothing to
// its height, what's in it easing down into place, and takes the view down
// with it until the sheet's top is 12px under the view's. The scroll is led
// by the height, frame by frame, from when the sheet reaches the view's foot
// to when it is whole: it scrolls only into room the sheet has made, so it
// never runs ahead to be held back and jump, nor stops short; and it is
// the view's own scrollTop, which WebKit animates where it won't a smooth
// scrollIntoView. The reader scrolling meanwhile has the view from then on.
function unrollSheet(view, sheet) {
const from = view.scrollTop, room = view.scrollHeight - view.clientHeight;
const to = Math.max(from, Math.min(from + sheet.getBoundingClientRect().top - view.getBoundingClientRect().top - 12, room));
const h = sheet.offsetHeight;
// how tall the sheet is when it reaches the view's foot, where the view
// can start to move: from there the view goes down as it grows
const x0 = Math.max(0, h - (room - from));
scrollOnPurpose(ROW_OPEN.ms + 300);
if (!h || matchMedia("(prefers-reduced-motion: reduce)").matches) { view.scrollTop = to; return; }
const pad = getComputedStyle(sheet);
sheet.style.overflow = "hidden";
const grow = sheet.animate([
{ height: "0px", paddingTop: "0px", paddingBottom: "0px" },
{ height: h + "px", paddingTop: pad.paddingTop, paddingBottom: pad.paddingBottom },
], { duration: ROW_OPEN.ms + 60, easing: `cubic-bezier(${ROW_OPEN.ease})` });
for (const c of sheet.children) {
c.animate([{ opacity: 0, transform: "translateY(-6px)" }, { opacity: 1, transform: "none" }],
{ duration: 340, delay: 60, easing: "cubic-bezier(.22, 1, .36, 1)", fill: "backwards" });
}
let set = from;
const follow = () => {
if (Math.abs(view.scrollTop - set) > 2) return; // the reader took it
const done = grow.playState === "finished";
view.scrollTop = Math.round(from + (to - from) * (done ? 1 : Math.min(1, Math.max(0, sheet.offsetHeight - x0) / (h - x0))));
set = view.scrollTop; // as far as there was room for
if (!done) requestAnimationFrame(follow);
};
const end = () => { sheet.style.overflow = ""; };
grow.finished.then(() => { end(); follow(); }, end);
requestAnimationFrame(follow);
}
// rollUpSheet closes it the other way, quicker, and then does what closing
// it does.
function rollUpSheet(sheet, then) {
if (matchMedia("(prefers-reduced-motion: reduce)").matches) return then();
const pad = getComputedStyle(sheet);
sheet.style.overflow = "hidden";
const a = sheet.animate([
{ height: sheet.offsetHeight + "px", paddingTop: pad.paddingTop, paddingBottom: pad.paddingBottom, opacity: 1 },
{ height: "0px", paddingTop: "0px", paddingBottom: "0px", opacity: 0 },
], { duration: ROLLUP.ms - 80, easing: `cubic-bezier(${ROLLUP.ease})`, fill: "forwards" });
// held shut until it is hidden, then let go, so it is never seen whole again
const done = () => { then(); a.cancel(); sheet.style.overflow = ""; };
a.finished.then(done, done);
}
// ---------- usage ----------
const PERIODS = [["today", "Today"], ["7d", "7 days"], ["30d", "30 days"], ["all", "All"]];