Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to scroll smoothly in to the top in react js

function App() {
	const myRef = createRef()
    
    function scroll(ref) {
    	ref.current.scrollIntoView({ behavior: 'smooth' })
  	}
  
    return (
      <div className="App scrollToHere" ref={myRef}>
        Content...
        .....
        .....
        <button onClick={() => scroll(myRef)}>top</button>
      </div>
  )
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #scroll #smoothly #top #react #js
ADD COMMENT
Topic
Name
8+2 =