scroll to id reactjs
import React, { useRef } from 'react'
const scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop)
// General scroll to element function
const ScrollDemo = () => {
const myRef = useRef(null)
const executeScroll = () => scrollToRef(myRef)
return (
<>
<div ref={myRef}>I wanna be seen</div>
<button onClick={executeScroll}> Click to scroll </button>
</>
)
}
class ReadyToScroll extends Component {
constructor(props) {
super(props)
this.myRef = React.createRef()
}
render() {
return <div ref={this.myRef}></div>
}
scrollToMyRef = () => window.scrollTo(0, this.myRef.current.offsetTop)
// run this method to execute scrolling.
}7786969876879
Also in JavaScript:
- javascript function multiple return
- Bind Json file into a Datagridview in windows form using C#
- local storage remove multiple items
- jquery nearest
- asynchronous javascript
- mongoose custom object schema
- from json timestamp to date python
- comment faire pour écrire un texte en javascript
- jquery val style
- javascript capitalize array
- nodejs express routing get
- javascript add to object
- how to make page scroll to the top jsx
- best react native animation library
- how to flatten nested arrays javascript
- install redux saga in react js
- what is json
- create new vuejs project
- how to get time and date from iso string javascript
- functional component react with state
- reverse an array javascript
- local storage javascript array
- how to put react compnent to bottom
- js create jaon object from for loop