mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-03 07:26:45 +00:00
hexo 关闭自动滚动
This commit is contained in:
@@ -15,7 +15,6 @@ const Header = props => {
|
|||||||
const [typed, changeType] = useState()
|
const [typed, changeType] = useState()
|
||||||
const { siteInfo } = props
|
const { siteInfo } = props
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
scrollTrigger()
|
|
||||||
updateHeaderHeight()
|
updateHeaderHeight()
|
||||||
if (!typed && window && document.getElementById('typed')) {
|
if (!typed && window && document.getElementById('typed')) {
|
||||||
changeType(
|
changeType(
|
||||||
@@ -29,45 +28,20 @@ const Header = props => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
window.addEventListener('scroll', scrollTrigger)
|
if (enableAutoScroll) {
|
||||||
|
scrollTrigger()
|
||||||
|
window.addEventListener('scroll', scrollTrigger)
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', updateHeaderHeight)
|
window.addEventListener('resize', updateHeaderHeight)
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('scroll', scrollTrigger)
|
if (enableAutoScroll) {
|
||||||
|
window.removeEventListener('scroll', scrollTrigger)
|
||||||
|
}
|
||||||
window.removeEventListener('resize', updateHeaderHeight)
|
window.removeEventListener('resize', updateHeaderHeight)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const autoScrollEnd = () => {
|
|
||||||
if (autoScroll) {
|
|
||||||
windowTop = window.scrollY
|
|
||||||
autoScroll = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动吸附滚动,移动端体验不好暂时关闭
|
|
||||||
*/
|
|
||||||
const scrollTrigger = () => {
|
|
||||||
if (screen.width <= 768) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const scrollS = window.scrollY
|
|
||||||
// 自动滚动
|
|
||||||
if ((scrollS > windowTop) & (scrollS < window.innerHeight) && !autoScroll
|
|
||||||
) {
|
|
||||||
autoScroll = true
|
|
||||||
window.scrollTo({ top: wrapperTop, behavior: 'smooth' })
|
|
||||||
setTimeout(autoScrollEnd, 500)
|
|
||||||
}
|
|
||||||
if ((scrollS < windowTop) && (scrollS < window.innerHeight) && !autoScroll) {
|
|
||||||
autoScroll = true
|
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
|
||||||
setTimeout(autoScrollEnd, 500)
|
|
||||||
}
|
|
||||||
windowTop = scrollS
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateHeaderHeight () {
|
function updateHeaderHeight () {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const wrapperElement = document.getElementById('wrapper')
|
const wrapperElement = document.getElementById('wrapper')
|
||||||
@@ -106,4 +80,37 @@ const Header = props => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const enableAutoScroll = false // 是否开启自动吸附滚动
|
||||||
|
|
||||||
|
const autoScrollEnd = () => {
|
||||||
|
if (autoScroll) {
|
||||||
|
windowTop = window.scrollY
|
||||||
|
autoScroll = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动吸附滚动,移动端体验不好暂时关闭
|
||||||
|
*/
|
||||||
|
const scrollTrigger = () => {
|
||||||
|
if (screen.width <= 768) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollS = window.scrollY
|
||||||
|
// 自动滚动
|
||||||
|
if ((scrollS > windowTop) & (scrollS < window.innerHeight) && !autoScroll
|
||||||
|
) {
|
||||||
|
autoScroll = true
|
||||||
|
window.scrollTo({ top: wrapperTop, behavior: 'smooth' })
|
||||||
|
setTimeout(autoScrollEnd, 500)
|
||||||
|
}
|
||||||
|
if ((scrollS < windowTop) && (scrollS < window.innerHeight) && !autoScroll) {
|
||||||
|
autoScroll = true
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
setTimeout(autoScrollEnd, 500)
|
||||||
|
}
|
||||||
|
windowTop = scrollS
|
||||||
|
}
|
||||||
|
|
||||||
export default Header
|
export default Header
|
||||||
|
|||||||
Reference in New Issue
Block a user