hexo 微调,添加随机跳转按钮

This commit is contained in:
tangly1024.com
2024-06-05 15:46:47 +08:00
parent eead53dbe0
commit 73a4e26daf
9 changed files with 133 additions and 42 deletions

View File

@@ -0,0 +1,36 @@
import { siteConfig } from '@/lib/config'
import CONFIG from '../config'
/**
* 跳转到评论区
* @returns {JSX.Element}
* @constructor
*/
const ButtonJumpToComment = () => {
if (!siteConfig('HEXO_WIDGET_TO_COMMENT', null, CONFIG)) {
return <></>
}
function navToComment() {
if (document.getElementById('comment')) {
window.scrollTo({
top: document.getElementById('comment').offsetTop,
behavior: 'smooth'
})
}
// 兼容性不好
// const commentElement = document.getElementById('comment')
// if (commentElement) {
// commentElement?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' })
}
return (
<div
className='flex space-x-1 items-center justify-center transform hover:scale-105 duration-200 w-7 h-7 text-center'
onClick={navToComment}>
<i className='fas fa-comment text-xs' />
</div>
)
}
export default ButtonJumpToComment