Tax Lawfirm Demo 1
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
'use client'
|
||||
|
||||
import {useEffect} from 'react'
|
||||
|
||||
export function useScrollTarget() {
|
||||
const scrollToSection = (id: string) => {
|
||||
if (id === 'top') {
|
||||
window.scrollTo({top: 0, behavior: 'smooth'})
|
||||
return
|
||||
}
|
||||
|
||||
const el = document.getElementById(id)
|
||||
if (el) {
|
||||
el.scrollIntoView({behavior: 'smooth', block: 'start'})
|
||||
}
|
||||
}
|
||||
|
||||
const handleSectionClick = (id: string) => {
|
||||
if (window.location.pathname !== '/') {
|
||||
localStorage.setItem('scrollTarget', id)
|
||||
window.location.href = '/'
|
||||
} else {
|
||||
scrollToSection(id)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const target = localStorage.getItem('scrollTarget')
|
||||
if (target) {
|
||||
localStorage.removeItem('scrollTarget')
|
||||
scrollToSection(target)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return {scrollToSection, handleSectionClick}
|
||||
}
|
||||
Reference in New Issue
Block a user