Skip to content

Commit ffd2891

Browse files
committed
Update toc height auto resize
1 parent 1af0db4 commit ffd2891

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

assets/css/screen.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,7 @@ body.nav-opened .site-wrapper {
15551555
}
15561556
.toc {
15571557
padding-bottom: 10px;
1558+
overflow-y: auto;
15581559
}
15591560
.toc a {
15601561
font-size: 14px;

assets/js/index.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
$(window).scroll(function() {
2323
var scrollerToTop = $('.backTop');
2424
var scrollerTOC = $('.widget-toc');
25-
document.documentElement.scrollTop + document.body.scrollTop > 200 ? scrollerToTop.fadeIn() : scrollerToTop.fadeOut();
26-
document.documentElement.scrollTop + document.body.scrollTop > 250 ? scrollerTOC.addClass("widget-toc-fixed") : scrollerTOC.removeClass("widget-toc-fixed");
25+
document.documentElement.scrollTop + document.body.scrollTop > 200 ?
26+
scrollerToTop.fadeIn() :
27+
scrollerToTop.fadeOut();
28+
document.documentElement.scrollTop + document.body.scrollTop > 250 ?
29+
scrollerTOC.addClass("widget-toc-fixed") :
30+
scrollerTOC.removeClass("widget-toc-fixed");
2731
});
2832

2933
// #backTop Button Event
@@ -46,13 +50,27 @@
4650
});
4751
});
4852

53+
var toc = $('.toc');
4954
// toc config
50-
$("#toc").toc({
55+
toc.toc({
5156
content: ".post-content",
5257
headings: "h2,h3,h4,h5"
5358
});
5459

55-
if ($("#toc").children().length == 0) $(".widget-toc").hide();
60+
if (toc.children().length == 0) $(".widget-toc").hide();
61+
62+
var tocHieght = toc.height();
63+
var tocFixedHeight = $(window).height() - 192;
64+
tocHieght > tocFixedHeight ?
65+
toc.css('height', tocFixedHeight) :
66+
toc.css('height', tocHieght)
67+
68+
$(window).resize(function() {
69+
var tocFixedHeight = $(this).height() - 192;
70+
tocHieght > tocFixedHeight ?
71+
toc.css('height', tocFixedHeight) :
72+
toc.css('height', tocHieght)
73+
})
5674

5775
// toc animate effect
5876
// bind click event to all internal page anchors
@@ -66,7 +84,7 @@
6684
$(target).velocity('scroll', {
6785
duration: 500,
6886
easing: 'ease-in-out'
69-
//easing: 'spring'
87+
//easing: 'spring'
7088
});
7189
});
7290

@@ -84,7 +102,7 @@
84102
locked: false
85103
}
86104
},
87-
beforeShow : function() {
105+
beforeShow: function() {
88106
var alt = this.element.find('img').attr('alt');
89107

90108
this.inner.find('img').attr('alt', alt);
@@ -99,11 +117,11 @@
99117
$.fn.arctic_scroll = function(options) {
100118

101119
var defaults = {
102-
elem: $(this),
103-
speed: 500
104-
},
120+
elem: $(this),
121+
speed: 500
122+
},
105123

106-
allOptions = $.extend(defaults, options);
124+
allOptions = $.extend(defaults, options);
107125

108126
allOptions.elem.click(function(event) {
109127
event.preventDefault();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "kaldorei",
33
"description": "A Simple And Elegant Ghost Theme Derive From Default Theme Casper",
44
"homepage": "https://github.com/xiaoluoboding/ghost-theme-kaldorei",
5-
"version": "0.6.0",
5+
"version": "0.7.5",
66
"author": {
77
"name": "xiaoluoboding",
88
"url": "https://github.com/xiaoluoboding"

0 commit comments

Comments
 (0)