中文

写给自己

最要紧的是慢慢来,
每一步都要看得见。

Typography · Vanilla JS + CSS

Hand-drawn circle

手绘圈注

Circle a phrase with a hand-drawn stroke.

Also searched as: 用笔把重点词圈起来, 手画的圈圈住关键词, 像老师用红笔圈重点, Rough Notation 那种手绘标注

AI Markdown (.md)
Placement
Article, Hero heading
Mood
Playful, Soft
Trigger
进入屏幕
Site types
个人网站, 博客, 作品集

How it works & accessibility

Draw an irregular SVG ellipse by animating its stroke dash offset from its full length to zero.

Best for: Article, Hero heading (进入屏幕).

Reduced motion: 不播画圈的过程,圈直接出现

Mobile & touch: 和桌面一样;被圈的词不折行,手机上挑短一点的词来圈

Key parameters

ParameterKeyDefaultRangeNotes
画圈时长duration700ms——
线宽thickness3px——
形状变化wobble4%——
缓动easingcubic-bezier(0.5, 0.05, 0.3, 1)——

Ready-to-paste AI prompt

Add “Hand-drawn circle” to the article in my project: Draw an irregular SVG ellipse by animating its stroke dash offset from its full length to zero.
Parameters: duration: 700ms, thickness: 3px, wobble: 4%, easing: cubic-bezier(0.5, 0.05, 0.3, 1).
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/hand-drawn-circle.md (canonical specification and reference code).

Dependency-free reference code

CSS
/* 手绘圈注的样式,配合 hand-drawn-circle.js。
   被圈的词在页面里本来就不折行(HTML 里给它 class="circled"):折成两行就圈不住了;
   要是等圈出现时才不折行,词会突然整个挪到下一行。
   圈是一层盖在词上面的 SVG:比词往外多出一点,不占位置,不挡点击。线的颜色用 --hd-color(默认是红笔的红);圆头的线,画到哪儿笔头就是圆的。 */
.circled {
  white-space: nowrap;
}
.hd-svg {
  position: absolute;
  left: -0.26em;
  top: -0.16em;
  width: calc(100% + 0.52em);
  height: calc(100% + 0.3em);
  overflow: visible;
  pointer-events: none;
}
.hd-svg path {
  fill: none;
  stroke: var(--hd-color, #e0301e);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
}
JavaScript
// 手绘圈注(Hand-drawn circle)· 原生 JS,不依赖任何库。
// 画线的做法改写自 StyleKit 的 hand-drawn-annotation(MIT License,Copyright (c) 2026 AnxForever;它的批注样子来自 syabro 的
// neat-annotations,MIT):一笔 SVG 线条,pathLength="1" 加 stroke-dasharray: 1,把 stroke-dashoffset 从 1 拨到 0,线就从起笔一路画到收笔。
// 圈的形状和本站开屏红笔圈名字的那一笔一样:起笔在左上,顺时针绕一圈,收笔越过起笔再往上挑。
// 每个圈的几个转折点各自随机挪一点("形状变化"),所以每个圈都略有不同;转折点连着两边的控制点一起挪,线还是顺的。
// 同一个圈在词变大变小时按原来那组随机数重画,形状不跳。
// el 是要圈的词(配合 hand-drawn-circle.css;词本身不折行,HTML 里给它 class="circled")。返回一个清理函数:调用它会拿掉这个圈。
// 圈只是装饰(aria-hidden):要让读屏也知道这是重点,被圈的词本身用 <strong> 或 <mark>。
// 开启"减少动态"时不画的过程,圈直接出现;脚本出错时也是画好的样子。ignoreReducedMotion 只给演示用。

// 一笔的形状:起点,然后九段三次贝塞尔(每段两个控制点、一个终点),坐标是 0–100 的比例,按词的实际大小换算,线宽不会被拉变形
const LOOP = [[16, 5.5], [40, 2.8, 72, 1.5, 90, 3], [97, 3.6, 99, 9, 99, 22], [99.2, 45, 99.6, 72, 96.5, 92], [95.5, 98, 85, 99.5, 58, 99.2], [35, 99, 16, 99.4, 7, 97], [1.8, 95.5, 1, 85, 1, 60], [1, 38, 0.8, 18, 4, 9.5], [6, 4.5, 12, 3.4, 22, 2.8], [27, 2.5, 31, 2, 35, 1.2]];
const NS = 'http://www.w3.org/2000/svg';

// 宽 w、高 h 的圈的路径。shift 是每个转折点挪多少([横, 竖],单位同样是 0–100 的比例):起点和第 k 段的终点用 shift[k],
// 第 k 段的第一个控制点跟着上一段的终点走(shift[k - 1]),第二个控制点跟着这一段的终点走,所以转折处还是顺的
export function loopPath(w, h, shift = LOOP.map(() => [0, 0])) {
  const p = (x, y, [dx, dy]) => `${(((x + dx) / 100) * w).toFixed(1)} ${(((y + dy) / 100) * h).toFixed(1)}`;
  const [m, ...cs] = LOOP;
  return `M${p(m[0], m[1], shift[0])}${cs.map(([a, b, c, d, e, f], i) => `C${p(a, b, shift[i])} ${p(c, d, shift[i + 1])} ${p(e, f, shift[i + 1])}`).join('')}`;
}

export function handDrawnCircle(el, {
  duration = 700,
  thickness = 3,
  wobble = 4,
  easing = 'cubic-bezier(0.5, 0.05, 0.3, 1)',
  ignoreReducedMotion = false,
} = {}) {
  const reduce = !ignoreReducedMotion && matchMedia('(prefers-reduced-motion: reduce)').matches;
  const svg = document.createElementNS(NS, 'svg');
  svg.setAttribute('class', 'hd-svg');
  svg.setAttribute('aria-hidden', 'true');
  const path = document.createElementNS(NS, 'path');
  path.setAttribute('pathLength', '1');
  path.style.strokeWidth = `${thickness}px`;
  svg.append(path);
  // 圈按词来摆:词没有定位时补上 relative(不改变位置);原来是 absolute 这类的不动
  const position = el.style.position;
  if (getComputedStyle(el).position === 'static') el.style.position = 'relative';
  el.append(svg);

  // 这个圈自己的一组随机数:每个转折点在 ±wobble 里挪一点
  const shift = LOOP.map(() => [(Math.random() * 2 - 1) * wobble, (Math.random() * 2 - 1) * wobble]);
  const fit = () => {
    const cs = getComputedStyle(svg);
    const w = parseFloat(cs.width);
    const h = parseFloat(cs.height);
    if (!w || !h) return;
    svg.setAttribute('viewBox', `0 0 ${w.toFixed(1)} ${h.toFixed(1)}`);
    path.setAttribute('d', loopPath(w, h, shift));
  };
  fit();
  // 词变大变小(字体后加载、窗口变宽换了字号、字改了):按同一组随机数重画,正在画的那一笔接着画。
  // 看的是圈自己(它的大小跟着词走):词一般是行内元素,ResizeObserver 看行内元素只报一次 0×0,之后变了也不报
  const resized = new ResizeObserver(fit);
  resized.observe(svg);

  let anim = null;
  if (!reduce) {
    try {
      anim = path.animate([{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }], { duration, easing, fill: 'backwards' });
    } catch {
      // 动画起不来(比如脚本出错):圈直接是画好的样子
    }
  }
  return () => {
    anim?.cancel();
    resized.disconnect();
    svg.remove();
    el.style.position = position;
  };
}

// 一个或一组词:各自整个露在屏幕里时开始画(只画一次)。圈不会把内容藏起来,所以不用提前开始,等看得见了再画,正好看到画的过程。
// root 是滚动的那个框,默认整个页面(document 按元素所在页面自己的视口算,放在 iframe 里也管用)。
/**
 * @param {Element | Iterable<Element>} els
 * @param {{ root?: Document | Element, duration?: number, thickness?: number, wobble?: number, easing?: string, ignoreReducedMotion?: boolean }} [options]
 */
export function handDrawnCircleOnView(els, { root = document, ...options } = {}) {
  const list = els instanceof Element ? [els] : [...els];
  const io = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      // 差一点点算整个露出来(有小数的位置,比例可能停在 0.99 几)
      if (!entry.isIntersecting || entry.intersectionRatio < 0.98) return;
      io.unobserve(entry.target);
      handDrawnCircle(entry.target, options);
    });
  }, { root, threshold: [0, 0.98, 1] });
  list.forEach((el) => io.observe(el));
  return () => io.disconnect();
}
HTML
<!-- 手绘圈注:给正文里的重点词调用一次,整个露在屏幕里时画一个手绘的圈。重点词本身用 <strong> 或 <mark>,读屏也知道它是重点 -->
<p>做网站最要紧的是<strong class="circled">慢慢来</strong>,每一步都看得见。</p>
<script type="module">
  import { handDrawnCircleOnView } from './hand-drawn-circle.js';
  handDrawnCircleOnView(document.querySelectorAll('.circled'));
</script>

More in Typography

Browse all 86 effects →

Shown once per release · Always available in changelog