HTML 設置 id,URL 加 #id 或 JS 設置 location.hash = 'id'。
const target = document.getElementById('section-3');
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
const rect = target.getBoundingClientRect();
window.scrollTo({ top: rect.top + window.scrollY, behavior: 'smooth' });
若需按行號跳轉,需預先建立行號與元素映射,或使用 document.getElementsByTagName('p')[lineNo] 定位。
現代瀏覽器支援 scrollIntoView 平滑滾動,兼容性好,優先使用。