This commit is contained in:
parent
c699f2ff85
commit
4abaf10a1b
@ -49,6 +49,15 @@ var Skin = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$articleToc.find('a').click(function (event) {
|
||||||
|
const id = $(this).attr('href')
|
||||||
|
window.location.hash = id
|
||||||
|
$(window).scrollTop($(id).offset().top - 60)
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
$(window).unbind('scroll').scroll(function (event) {
|
$(window).unbind('scroll').scroll(function (event) {
|
||||||
if ($articleProgress.length === 0) {
|
if ($articleProgress.length === 0) {
|
||||||
return false
|
return false
|
||||||
@ -82,14 +91,14 @@ var Skin = {
|
|||||||
$articleTocs.each(function (i) {
|
$articleTocs.each(function (i) {
|
||||||
toc.push({
|
toc.push({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
offsetTop: this.offsetTop,
|
offsetTop: $(this).offset().top,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 当前目录样式
|
// 当前目录样式
|
||||||
var scrollTop = $(window).scrollTop()
|
var scrollTop = $(window).scrollTop()
|
||||||
for (var i = 0, iMax = toc.length; i < iMax; i++) {
|
for (var i = 0, iMax = toc.length; i < iMax; i++) {
|
||||||
if (scrollTop < toc[i].offsetTop) {
|
if (scrollTop < toc[i].offsetTop - 61) {
|
||||||
$articleToc.find('li').removeClass('current')
|
$articleToc.find('li').removeClass('current')
|
||||||
var index = i > 0 ? i - 1 : 0
|
var index = i > 0 ? i - 1 : 0
|
||||||
$articleToc.find('a[href="#' + toc[index].id + '"]').
|
$articleToc.find('a[href="#' + toc[index].id + '"]').
|
||||||
@ -98,7 +107,7 @@ var Skin = {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scrollTop >= toc[toc.length - 1].offsetTop) {
|
if (scrollTop >= toc[toc.length - 1].offsetTop - 61) {
|
||||||
$articleToc.find('li').removeClass('current')
|
$articleToc.find('li').removeClass('current')
|
||||||
$articleToc.find('li:last').addClass('current')
|
$articleToc.find('li:last').addClass('current')
|
||||||
}
|
}
|
||||||
@ -107,4 +116,4 @@ var Skin = {
|
|||||||
$(window).scroll()
|
$(window).scroll()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Skin.init();
|
Skin.init()
|
Loading…
x
Reference in New Issue
Block a user