diff --git a/layouts/ArticleLayout.js b/layouts/ArticleLayout.js
index 885c1546..c4c4bf62 100644
--- a/layouts/ArticleLayout.js
+++ b/layouts/ArticleLayout.js
@@ -45,7 +45,7 @@ const ArticleLayout = ({
diff --git a/layouts/DefaultLayout.js b/layouts/DefaultLayout.js
index c4bd16ef..77b7cc25 100644
--- a/layouts/DefaultLayout.js
+++ b/layouts/DefaultLayout.js
@@ -5,8 +5,9 @@ import BLOG from '@/blog.config'
import CommonHead from '@/components/CommonHead'
import { useRouter } from 'next/router'
import { useTheme } from '@/lib/theme'
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
import SideBar from '@/components/SideBar'
+import throttle from 'lodash.throttle'
const DefaultLayout = ({ tags, posts, page, currentTag, ...customMeta }) => {
const meta = {
@@ -49,7 +50,24 @@ const DefaultLayout = ({ tags, posts, page, currentTag, ...customMeta }) => {
if (ref) {
ref.remove()
}
- })
+ window.addEventListener('resize', resizeWindowHideToc)
+ resizeWindowHideToc()
+ return () => {
+ window.removeEventListener('resize', resizeWindowHideToc)
+ }
+ }, [])
+
+ const resizeWindowHideToc = throttle(() => {
+ if (window.innerWidth > 1300) {
+ changeColumn(3)
+ } else if (window.innerWidth < 768) {
+ changeColumn(1)
+ } else {
+ changeColumn(2)
+ }
+ }, 500)
+
+ const [column, changeColumn] = useState(1)
const { theme } = useTheme()
@@ -59,7 +77,7 @@ const DefaultLayout = ({ tags, posts, page, currentTag, ...customMeta }) => {
{/*
*/}
{/*
*/}
-
+
@@ -91,12 +109,13 @@ const DefaultLayout = ({ tags, posts, page, currentTag, ...customMeta }) => {
{/* 文章列表 */}
-
+ {/*
*/}
+
{!postsToShow.length && (
No posts found.
)}
{postsToShow.map(post => (
-
+
))}
diff --git a/styles/globals.css b/styles/globals.css
index 2e826ef0..9c530ee4 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -111,6 +111,10 @@ nav {
@media (max-width: 1300px){
.sidebar{
+ -ms-overflow-style: none;
+ overflow: -moz-scrollbars-none;
@apply border-r border-gray-200 h-screen overflow-y-scroll fixed left-0
}
+ .sidebar::-webkit-scrollbar { width: 0 !important }
}
+