Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
大白技术控
yanglr2010
提交
1e242b3c
Y
yanglr2010
项目概览
大白技术控
/
yanglr2010
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yanglr2010
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1e242b3c
编写于
6月 28, 2019
作者:
EvanOne(文一)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: Fold toc by default & spread it auto when heading to the top
上级
84247f10
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
20 deletion
+66
-20
source/css/_common/sidebar.styl
source/css/_common/sidebar.styl
+26
-17
source/js/scroll.js
source/js/scroll.js
+40
-3
未找到文件。
source/css/_common/sidebar.styl
浏览文件 @
1e242b3c
$sidebar-float = convert(
hexo-config('sidebar.position') || 'right')
$sidebar-width = convert(
hexo-config('sidebar.width') || '300px')
$sidebar-float = convert(hexo-config('sidebar.position') || 'right')
$sidebar-width = convert(hexo-config('sidebar.width') || '300px')
#sidebar
float: $sidebar-float
width: $sidebar-width
font-size: $font-sidebar-base
$sidebar-top = convert(
hexo-config('sidebar.offsetTop') || '30px')
$sidebar-top = convert(hexo-config('sidebar.offsetTop') || '30px')
.sidebar-inner
border-radius: 5px
...
...
@@ -56,7 +53,22 @@ else
overflow: auto
max-height: 50vh
@extend $toc-word-break
.toc .toc-child
display: none
.toc .active > .toc-child
display: block
.toc .current > .toc-child
display: block
.active,
.current
& > a
color: $orange-dark
transition: color .3s
ol,
li
list-style: none
...
...
@@ -66,14 +78,13 @@ else
padding-left: 1em
$avatar-rounded = 0
if (hexo-config('author.avatar.rounded'))
$avatar-rounded = 50%
$avatar-opacity = hexo-config('author.avatar.opacity') || 1
$avatar-animation = 'avatar-' + convert(
hexo-config('author.avatar.animation') || 'turn')
$text-align = convert(
hexo-config('social_setting.text_align') || 'center')
$avatar-animation = 'avatar-' + convert(hexo-config('author.avatar.animation') || 'turn')
$text-align = convert(hexo-config('social_setting.text_align') || 'center')
.sidebar-overview
.sidebar-author
...
...
@@ -131,9 +142,9 @@ $text-align = convert(
display: inline
if (hexo-config('social_setting.icon_only'))
background-color: $sidebar-social-color
border-radius: 50%
line-height: 1.5rem
background-color: $sidebar-social-color
&:hover
background-color: $sidebar-social-hover-color
...
...
@@ -158,7 +169,7 @@ $text-align = convert(
i
width: 1.2rem
&:hover
background-color: $sidebar-social-color
...
...
@@ -235,10 +246,8 @@ $text-align = convert(
margin-top: 0
padding-top: 0
$reading_progress_color = convert(
hexo-config('reading_progress.color') || '$blue-light')
$reading_progress_height = convert(
hexo-config('reading_progress.height') || '1px')
$reading_progress_color = convert(hexo-config('reading_progress.color') || '$blue-light')
$reading_progress_height = convert(hexo-config('reading_progress.height') || '1px')
.sidebar-progress
margin-top: .5em
...
...
source/js/scroll.js
浏览文件 @
1e242b3c
...
...
@@ -14,24 +14,29 @@ $(document).ready(function () {
// Must initial run
readProgress
();
sidebarSticky
();
autoSpreadToc
();
var
currHeading
=
null
;
var
lastHeading
=
null
;
$
(
window
).
scroll
(
function
()
{
readProgress
();
sidebarSticky
();
autoSpreadToc
();
});
// click heading
$
(
'
.main-content
'
)
.
find
(
'
h1,h2,h3,h4,h5,h6
'
)
.
on
(
'
click
'
,
function
()
{
scroll
ToHead
(
'
#
'
+
$
(
this
).
attr
(
'
id
'
))
scroll
HeadingToTop
(
'
#
'
+
$
(
this
).
attr
(
'
id
'
))
});
// click post toc
$
(
'
.toc-link
'
).
on
(
'
click
'
,
function
(
e
)
{
e
.
preventDefault
();
scroll
ToHead
(
$
(
this
).
attr
(
'
href
'
));
scroll
HeadingToTop
(
$
(
this
).
attr
(
'
href
'
));
});
$
(
'
#back-top
'
).
click
(
function
()
{
...
...
@@ -110,8 +115,40 @@ $(document).ready(function () {
$
(
'
.sidebar-progress-line
'
).
css
(
'
width
'
,
percent
);
}
// Automatically expand items in the article directory
// based on the scrolling of heading in the article
function
autoSpreadToc
()
{
if
(
$
(
'
.post-body
'
).
find
(
'
h1,h2,h3,h4,h5,h6
'
)
.
first
().
offset
().
top
-
$
(
window
).
scrollTop
()
>
0
)
{
$
(
'
.sidebar-toc li
'
).
removeClass
(
'
active current
'
);
return
;
}
$
(
'
.post-body
'
).
find
(
'
h1,h2,h3,h4,h5,h6
'
)
.
each
(
function
(
index
,
item
)
{
var
top
=
item
.
getBoundingClientRect
().
top
;
if
(
top
<
0
)
{
currHeading
=
$
(
item
).
attr
(
'
id
'
);
}
});
if
(
currHeading
===
lastHeading
)
{
return
;
}
else
{
$
(
'
.sidebar-toc li
'
).
removeClass
(
'
active current
'
);
$
(
`.sidebar-toc a[href="#
${
currHeading
}
"]`
)
.
parents
(
'
li
'
).
addClass
(
'
active
'
);
$
(
`.sidebar-toc a[href="#
${
currHeading
}
"]`
)
.
parent
().
addClass
(
'
current
'
);
lastHeading
=
currHeading
;
}
}
// scroll heading to top
function
scroll
ToHead
(
anchor
)
{
function
scroll
HeadingToTop
(
anchor
)
{
$
(
anchor
)
.
velocity
(
'
stop
'
)
.
velocity
(
'
scroll
'
,
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录