---
title: "滚动讲解"
subtitle: "<ScrollWalkthrough>（别名 <Walkthrough>）边滚动边讲解代码，代码面板跟随当前步骤高亮。"
---

滚动驱动的讲解（别名 `<Walkthrough>`）：左侧是步骤，右侧是跟随当前步骤高亮的代码面板。每个围栏代码块是面板中的一个文件（语言后的文字是文件名）。

````mdx
<ScrollWalkthrough>
  <Step title="创建客户端" file="deploy.ts" focus="1-3">
    读取 API Key 与平台地址。
  </Step>
  <Step title="上传" focus="5-10">
    以 gzip tar 包上传源码，得到部署 id。
  </Step>
  <Step title="等待完成" focus="12-17">
    每秒查询一次状态，直到 ready 或 failed。
  </Step>

  ```ts deploy.ts
  const api = process.env.BITI_API ?? "https://console.butterix.com";
  …
  ```
</ScrollWalkthrough>
````

<ScrollWalkthrough>
  <Step title="创建客户端" file="deploy.ts" focus="1-3">
    读取 API Key 与平台地址。
  </Step>
  <Step title="上传" focus="5-10">
    以 gzip tar 包上传源码，得到部署 id。
  </Step>
  <Step title="等待完成" focus="12-17">
    每秒查询一次状态，直到 ready 或 failed。
  </Step>

  ```ts deploy.ts
  const api = process.env.BITI_API ?? "https://console.butterix.com";
  const token = process.env.BITI_TOKEN!;
  const headers = { authorization: `Bearer ${token}` };

  const res = await fetch(`${api}/api/v1/sites/acme-payments/deployments`, {
    method: "POST",
    headers: { ...headers, "content-type": "application/gzip", "x-biti-preview": "1" },
    body: await readFile("site.tgz"),
  });
  const { id } = await res.json();

  for (;;) {
    await new Promise((r) => setTimeout(r, 1000));
    const d = await (await fetch(`${api}/api/v1/deployments/${id}`, { headers })).json();
    if (d.status === "ready") { console.log(d.url); break; }
    if (d.status === "failed") throw new Error(d.error);
  }
  ```
</ScrollWalkthrough>

<ParamField path="layout" type="default | wide" default="default">`wide` 让代码面板更宽。</ParamField>
<ParamField path="panelHeight" type="string">代码面板高度，例如 `32rem`。</ParamField>
<ParamField path="stickyHeaders" type="boolean" default="true">子步骤滚动时固定步骤标题。</ParamField>
<ParamField path="dim" type="boolean" default="true">淡化非当前步骤。</ParamField>
<ParamField path="substepStyle" type="step | bullet" default="step">子步骤用编号还是圆点。</ParamField>

`<Step>` 在这里额外支持 `file`（文件名或从 0 开始的序号）、`focus`、`highlight`、`startLine`；步骤内可以再放 `<Substep title file focus highlight startLine id>`（别名 `<SubStep>`）细分。
