容器固定高度、內容超出顯示滾動條,純 CSS 即可,無需 JS。
#event_basicInfo {
height: 400px; /* 固定高度 */
overflow: auto; /* 超出自動滾動 */
/* width: 40%; */ /* 可選寬度 */
}
function setHeight(){
const div = document.getElementById('event_basicInfo');
div.style.height = '400px';
div.style.overflow = 'auto';
}
window.onload = setHeight;
overflow-y: auto; /* 僅垂直滾動 */
overflow-x: hidden; /* 隱藏水平滾動 */
max-height),否則 overflow:auto 不生效。::-webkit-scrollbar 偽元素自定義(WebKit 內核)。-webkit-overflow-scrolling: touch 啟用慣性滾動。