PageSourceSearch

https://www.nihondo.co.jp/assets/js/anchor-link.js

js nihondo.co.jp collected 2026-10-02 10:17:36 UTC 827 bytes, 18 lines download raw bytes

1// 同一ページ内アンカーリンクのスクロール処理。
2// URL ハッシュは更新するが履歴には積まない (replaceState) ため、
3// 戻るボタンでアンカー移動が巻き戻らず前ページへ直接戻れる。
4export function anchorLink() {
5  document.querySelectorAll('a[href^="#"]').forEach((link) => {
6    link.addEventListener('click', (e) => {
7      const href = link.getAttribute('href');
8      if (!href || href === '#') return;
9      const target = document.getElementById(href.slice(1));
10      if (!target) return;
11      e.preventDefault();
12      // behavior は指定せず CSS の scroll-behavior に委ねる
13      // (prefers-reduced-motion 設定が反映される)
14      target.scrollIntoView({ block: 'start' });
15      history.replaceState(null, '', href);
16    });
17  });
18}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.