how to scroll to an element javascript react
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>
</>
)
}
import { scroller } from "react-scroll";
// excluded React component syntax...
scrollToSection = () => {
scroller.scrollTo("your_css_class_here", {
duration: 800,
delay: 0,
smooth: "easeInOutQuart",
});
};
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.
}
Also in JavaScript:
- how to display first value of an array in jquery
- javascript array find highest value of array of objects by key
- angry professor javascript
- how to select the first div in jQuery
- initialize a map js
- vendor bundle base js and bootstrap min js conflict
- javascript insertBefore
- javascript object get value by key
- react native map array of objects
- logical operators javascript
- list pci express version command line
- javascript random number between 0 and 10
- javascript is object
- jquery add text to textbox
- do i have to include jquery files at head of bootstrap
- comentário jsx
- excel date to javascript date
- how to right plain text format file in node js
- drupal 8 get url from node entity
- javascript base64 encode string
- json_encode escape \
- js !==
- debugger js
- jwt refresh token