mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-05 07:26:46 +00:00
Merge pull request #156 from tangly1024/bug-scroll-comment-button
bug-滚动到评论区
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import CONFIG_HEXO from '../config_hexo'
|
import CONFIG_HEXO from '../config_hexo'
|
||||||
|
let wrapperTop = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 跳转到评论区
|
* 跳转到评论区
|
||||||
@@ -10,16 +11,30 @@ const JumpToCommentButton = () => {
|
|||||||
if (!CONFIG_HEXO.WIDGET_TO_COMMENT) {
|
if (!CONFIG_HEXO.WIDGET_TO_COMMENT) {
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
function navToComment () {
|
|
||||||
const commentElement = document.getElementById('comment')
|
function updateHeaderHeight() {
|
||||||
if (commentElement) {
|
setTimeout(() => {
|
||||||
commentElement?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' })
|
if (window) {
|
||||||
}
|
const wrapperElement = document.getElementById('comment')
|
||||||
|
wrapperTop = wrapperElement?.offsetTop
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
function navToComment() {
|
||||||
|
window.scrollTo({ top: wrapperTop, 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} >
|
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' />
|
<i className='fas fa-comment text-xs' />
|
||||||
</div>)
|
</div>)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default JumpToCommentButton
|
export default JumpToCommentButton
|
||||||
|
|||||||
Reference in New Issue
Block a user