本文修改主题为Butterfly
主题,若使用其他主题,请自行确认修改位置。
原文出处
https://akilar.top/posts/397b8b90/
效果预览
查看图片
修改步骤
1. 新建文件
新建[Blogroot]\themes\butterfly\source\css\custom\fixed_comment.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| div#post-comment.fixedcomment { position: fixed; top: 0; width: 60%; right: 0; padding: 25px 30px 20px 20px; height: 100vh; overflow: scroll; z-index: 90; background: rgba(222, 222, 222, 0.95); box-shadow:3px 2px 14px #464340; animation: fixedright 0.5s linear; } div#post-comment.fixedcomment::-webkit-scrollbar { width: 0; } div#quit-board{ display: none; } div#quit-board.fixedcomment { position: fixed; display:block!important; left: 0; top: 0; width: 40%; height: 100vh; z-index: 89!important; background: rgba(25,25,25,0.3); filter: blur(4px) !important; animation: fixedleft 0.5s linear; }
@media screen and (max-width: 768px) { div#post-comment.fixedcomment { width: 90%; right: 0; } div#quit-board.fixedcomment { width: 10%; } }
@keyframes fixedright { from {right:-50%;} to {right:0;} } @keyframes fixedleft { from {left:-50%;} to {left:0;} }
[data-theme="dark"] div#post-comment.fixedcomment { background: rgba(35, 35, 35, 0.95); box-shadow:3px 2px 12px #90a1a4; } [data-theme="dark"] div#quit-board.fixedcomment { background: rgba(147, 146, 128, 0.3); }
|
新建[Blogroot]\themes\butterfly\source\js\custom\fixed_comment.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| function RemoveFixedComment() { var activedItems = document.querySelectorAll('.fixedcomment'); if (activedItems) { for (i = 0; i < activedItems.length; i++) { activedItems[i].classList.remove('fixedcomment'); } } }
function AddFixedComment(){ var commentBoard = document.getElementById('post-comment'); var quitBoard = document.getElementById('quit-board'); commentBoard.classList.add('fixedcomment'); quitBoard.classList.add('fixedcomment'); }
function CreateQuitBoard(){ var quitBoard = `<div id="quit-board" onclick="RemoveFixedComment()"></div>` var commentBoard = document.getElementById('post-comment'); commentBoard.insertAdjacentHTML("beforebegin",quitBoard) }
function FixedCommentBtn(){ var commentBoard = document.getElementById('post-comment'); if (commentBoard) { if (commentBoard.className.indexOf('fixedcomment') > -1){ RemoveFixedComment(); } else{ CreateQuitBoard(); AddFixedComment(); } } else{ if (pjax){ pjax.loadUrl("/comments/#post-comment"); } else{ window.location.href = "/comments/#post-comment"; } } }
RemoveFixedComment();
|
2. 修改文件
修改[Blogroot]\_config.butterfly.yml
的inject
配置项,添加引入的js和css
注意:fixed_comment.js 有前置依赖且需要排除 pjax ,故插入 js 时应当加入 data-pjax 和 defer 标签
1 2 3 4 5
| inject: head: + - <link rel="stylesheet" href="/css/custom/fixed_comment.css" media="defer" onload="this.media='all'"> bottom: + - <script data-pjax defer src="/js/custom/fixed_comment.js"></script>
|
修改[Blogroot]\themes\butterfly\layout\includes\rightside.pug
,大约第36行的位置
1 2 3
| if commentsJsLoad - a#to_comment(href="#post-comment" title=_p("rightside.scroll_to_comment")) + button#to_comment(type="button" title=_p("rightside.scroll_to_comment") onclick="FixedCommentBtn();")
|