billion邮局

billion邮局的专属教程

// 修正Enlighter滚动条作用域(工具栏固定,只有代码滚动) (function() { function fixEnlighterScroll() { // 找到所有Enlighter代码块容器 var containers = document.querySelectorAll('.enlighter-default'); for (var i = 0; i < containers.length; i++) { var container = containers[i]; var codeBlock = container.querySelector('.enlighter'); if (!codeBlock) continue; // 获取父容器的滚动条设置 var containerStyle = window.getComputedStyle(container); var containerMaxHeight = containerStyle.maxHeight; var containerOverflowY = containerStyle.overflowY; // 如果父容器有滚动条设置,将其移动到代码块上 if (containerOverflowY === 'auto' && containerMaxHeight !== 'none') { // 将滚动条样式从父容器移到代码块 container.style.maxHeight = 'none'; container.style.overflowY = 'visible'; codeBlock.style.maxHeight = containerMaxHeight; codeBlock.style.overflowY = 'auto'; } } } // 等待Enlighter初始化完成后执行 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { // 延迟执行,确保Enlighter已经渲染完成 setTimeout(fixEnlighterScroll, 100); }); } else { setTimeout(fixEnlighterScroll, 100); } // 监听动态内容加载(如折叠/展开) if (window.MutationObserver) { var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'attributes' && mutation.attributeName === 'class') { var target = mutation.target; if (target.classList && target.classList.contains('enlighter-raw')) { // 折叠/展开后重新修正 setTimeout(fixEnlighterScroll, 50); } } }); }); // 监听所有代码块容器 document.querySelectorAll('.enlighter-default').forEach(function(container) { observer.observe(container, { attributes: true, attributeFilter: ['class'] }); }); } })();