多組登入表單(管理員、一般用戶等)以標籤切換,切換過程帶有高度收合/展開、垂直位移的雙重動畫,視覺層次豐富,類似早期入口網站會員區設計。
temp_num(舊面板)、now_num(新面板)、no_can_do 防重入鎖。pixelHeight - 6)至 1px。pixelTop - 1)、新標籤下移(pixelTop + 1)至目標位置。+6)至 182px,顯示表單。set_menu() 推進動畫,完成後 clearInterval 釋放鎖。function Show_menu(u_num, d_num) {
if (no_can_do) return;
now_num = d_num;
if (temp_num) clearInterval(document.getElementById('menu_' + temp_num).doing);
else temp_num = u_num;
document.getElementById('menu_' + temp_num).doing = setInterval(set_menu, 10);
}
function set_menu() {
no_can_do = true;
document.getElementById('form_' + temp_num).style.display = 'none';
var h = document.getElementById('div_' + temp_num).style.pixelHeight - 6;
if (h > 1) { document.getElementById('div_' + temp_num).style.pixelHeight = h; }
else {
// 階段 2:標籤位移
// 階段 3:新面板展開
}
}
// CSS Transition 版
.tab-panel { height: 0; overflow: hidden; transition: height 0.3s ease; opacity: 0; }
.tab-panel.active { height: auto; opacity: 1; }
// JS 僅切換 class
function switchTab(index) {
document.querySelectorAll('.tab-panel').forEach((p, i) => p.classList.toggle('active', i === index));
}
將動畫邏輯移至 CSS,JS 僅管狀態,程式碼從百行縮減至十行,維護性大幅提升。