跳到评论区

This commit is contained in:
tangly1024
2022-04-07 09:39:26 +08:00
parent a4478259aa
commit ed73eae3cf
4 changed files with 11 additions and 22 deletions

View File

@@ -1,6 +1,5 @@
import React, { useEffect } from 'react'
import React from 'react'
import CONFIG_HEXO from '../config_hexo'
let wrapperTop = 0
/**
* 跳转到评论区
@@ -12,26 +11,16 @@ const JumpToCommentButton = () => {
return <></>
}
function updateHeaderHeight() {
setTimeout(() => {
if (window) {
const wrapperElement = document.getElementById('comment')
wrapperTop = wrapperElement?.offsetTop
}
}, 500)
}
function navToComment() {
window.scrollTo({ top: wrapperTop, behavior: 'smooth' })
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' })
}
useEffect(() => {
updateHeaderHeight()
})
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>)