아래 링크 글을 보고 추가했습니다.
https://maroenispace.tistory.com/250
티스토리 프라치노 공간 스킨에 TOC(목차) 추가하는 방법
예전에 사용하던 JB스킨에는 TOC(Table Of Content) 목차가 기본적으로 지원되어서 On/Off 기능을 통해 쉽게 적용할 수 있었는데, 새로 구매한 프라치노 공간 스킨은 TOC가 없다는 게 정말 아쉬웠습니다.
maroenispace.tistory.com
라이브러리를 최신 버전으로 변경했습니다.
<!-- tocbot -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.css">
<!-- tocbot -->
스크립트에 오류가 있어 내용을 일부 수정했습니다.
<script>
var content = document.querySelector('#article');
if (content) {
var headings = content.querySelectorAll('h1, h2, h3, h4, h5, h6, h7');
var headingMap = {};
Array.prototype.forEach.call(headings, function (heading) {
var id = heading.id ? heading.id : heading.textContent.trim().toLowerCase().split(' ').join('-').replace(/[\!\@\#\$\%\^\&\*\(\):]/ig, '');
headingMap[id] = !isNaN(headingMap[id]) ? ++headingMap[id] : 0;
if (headingMap[id]) {
heading.id = id + '-' + headingMap[id];
} else {
heading.id = id;
}
});
tocbot.init({ tocSelector: '.toc', contentSelector: '#article', headingSelector:'h1, h2, h3', hasInnerContainers: false });
$(document).ready(function(){
$('.toc').addClass('toc-absolute');
var toc_top = $('.toc').offset().top - 165;
$(window).scroll(function() {
if ($(this).scrollTop() >= toc_top) {
$('.toc').addClass('toc-fixed');
$('.toc').removeClass('toc-absolute');
} else {
$('.toc').addClass('toc-absolute');
$('.toc').removeClass('toc-fixed');
}
});
});
}
</script>
'정보' 카테고리의 다른 글
이미지가 없는 글에 대체 이미지 보여주기 (0) | 2023.03.12 |
---|---|
프라치노 공간 커스텀 CSS (0) | 2023.03.12 |
프라치노 공간 다크 테마 배경색 변경 (0) | 2022.08.19 |
블랙베리 키투 키보드 팁 (0) | 2018.11.23 |
윈도우 10 무선랜 끊김 문제 해결 (0) | 2018.02.22 |
다이소 접시 꽂이로 타블렛 정리하기 (0) | 2018.02.11 |