Firefox 首頁點擊換膚按鈕後,頁面頂部平滑滑出一個面板展示主題縮圖,再次點擊或點擊外部則滑回收合。
body 頂端置入一個 div#themePanel,預設 height: 0; overflow: hidden;。.open。height 從 0 變為目標高度(如 300px)。transform: translateY() 配合 will-change,避免重排。#themePanel {
position: fixed; top: 0; left: 0; right: 0;
height: 0; overflow: hidden;
background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15);
transition: height .3s ease-out;
z-index: 1000;
}
#themePanel.open { height: 300px; }
const btn = document.getElementById('themeBtn');
const panel = document.getElementById('themePanel');
btn.addEventListener('click', () => panel.classList.toggle('open'));
// 點擊面板外部關閉
document.addEventListener('click', e => {
if (!panel.contains(e.target) && !btn.contains(e.target)) panel.classList.remove('open');
});
若需如 Firefox 般的彈性感,可使用 cubic-bezier(0.34, 1.56, 0.64, 1) 或引入 anime.js/GSAP 實現彈簧動畫。