- Forums
- react
- React Vite - How to Add Scroll Functionality onClick Button To Element Div
use this code to animate the scroll feature in a react application [5195], Last Updated: Mon Jun 24, 2024
cathy
Tue Aug 29, 2023
0 Comments
294 Visits
The only code that work for me in a Vite React application was this code:
useEffect(() => {
document.getElementById('top').scrollIntoView({ behavior: 'smooth' })
}, []);
return (
<div id="top">
.....code
What did not work:
window.scroll({top:0,behavior:'smooth'})
window.scrollTo(0, 0);
document.querySelector('body').scrollTo(0,0)