Skip to content

Commit

Permalink
✨ feat: 适配表格
Browse files Browse the repository at this point in the history
  • Loading branch information
Waite0603 authored and AirboZH committed Jan 24, 2024
1 parent d15db65 commit 8d862f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/js/patch/table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function addClassToTable() {
// 获取所有 content 下的 table 元素
const tables = document.querySelectorAll('.content table');

// 遍历所有 table 元素
tables.forEach((table) => {
// 创建一个 div 元素
const wrapper = document.createElement('div');
// 添加 class 属性
wrapper.classList.add('table-wrapper');
// 添加 text-align: cneter
wrapper.style.textAlign = 'center';
// 将 table 元素包裹在 div 元素内
table.parentNode.insertBefore(wrapper, table);
wrapper.appendChild(table);
});
}
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import {categoryCollapse} from "./js/modules/components/category-collapse";
import {imgLazy} from "./js/modules/components/img-lazyload";
import {toc} from "./js/modules/components/toc";
import {initClipboard} from "./js/modules/plugins";
// 因为 patch/index 中有内容且没有引用, 所有没有在 index 中引入
// 完善后以下代码应改为 import { * } from './js/patch/index';
import {activeSidebar} from "./js/patch/sidebar";
import {addClassToTable} from './js/patch/table';

basic();
initSidebar();
activeSidebar();
initTopbar();
addClassToTable();
categoryCollapse();
imgLazy();
// imgPopup();
Expand Down

0 comments on commit 8d862f3

Please sign in to comment.