傳統評論表單一次性展示所有欄位 (姓名、Email、網站、驗證碼、評論框...),視覺壓力大、認知負荷高、移動端佔據大量螢幕空間,導致使用者放棄發表。折疊表單透過「漸進式揭露」,僅在需要時顯示相關欄位,顯著提升參與度。
預設僅顯示核心輸入框——評論內容。
<form class="comment-form">
<textarea class="comment-input" placeholder="寫下你的想法..." aria-label="評論內容"></textarea>
<div class="comment-form-expanded" hidden>
<!-- 其餘欄位 -->
</div>
</form>
使用者點擊/聚焦評論框 → 平滑展開完整表單,**焦點保持在評論框** (關鍵:行為發生在交互產生最近處)。
const input = document.querySelector('.comment-input');
const expanded = document.querySelector('.comment-form-expanded');
input.addEventListener('focus', () => {
if (expanded.hidden) {
expanded.hidden = false;
// 強制重繪啟動動畫
requestAnimationFrame(() => {
expanded.style.height = 'auto';
const h = expanded.offsetHeight;
expanded.style.height = '0';
requestAnimationFrame(() => {
expanded.style.transition = 'height 0.3s ease';
expanded.style.height = h + 'px';
});
});
}
});
展開時,評論框以彈性動畫 (scale 1.02 → 1) 或邊框高亮脈動,明確引導使用者注意力回到輸入區。
.comment-input:focus {
animation: focus-pulse 0.6s ease-out;
}
@keyframes focus-pulse {
0% { box-shadow: 0 0 0 0 rgba(31, 96, 91, 0.4); }
70% { box-shadow: 0 0 0 8px rgba(31, 96, 91, 0); }
100% { box-shadow: 0 0 0 0 rgba(31, 96, 91, 0); }
}
表單固定於視窗頂部 (或文章末尾固定區),展開時向下推開內容,而非覆蓋。適合長文閱讀場景,使用者閱讀至末尾自然看到評論區。
<label> (可視或 aria-label/aria-labelledby)。aria-expanded="true/false"、aria-controls="expanded-panel-id"。@media (prefers-reduced-motion: reduce) 即時完成。aria-live="assertive"、關聯 aria-describedby。aria-busy="true"、顯示 Spinner、禁用輸入。折疊表單不只是「省空間」,更是「尊重使用者認知頻寬」。從核心動作開始,按需揭露輔助欄位,配合精心編排的動畫引導,能讓評論從「負擔」變為「自然延伸的表達」。