“desplazarse a la sección Reaccionar” Código de respuesta

reaccionar cómo desplazarse al elemento

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> 
      </>
   )
}
Graceful Grasshopper

Cómo desplazarse a un elemento JavaScript Reaccion

import { scroller } from "react-scroll";

// excluded React component syntax...

  scrollToSection = () => {
    scroller.scrollTo("your_css_class_here", {
      duration: 800,
      delay: 0,
      smooth: "easeInOutQuart",
    });
  };
Mr Dojo

desplazarse a la sección Reaccionar

import React, { useRef } from 'react'

const scrollToRef = (ref) => window.scrollTo({ top: ref.current.offsetTop, behavior: "smooth" })   
// General scroll to element function

const ScrollToSection = () => {

   const sectionRef = useRef(null)
   const executeSectionScroll = () => scrollToRef(myRef)

   return (
      <> 
         <div ref={sectionRef}>I wanna be seen</div> 
         <button onClick={executeSectionScroll}> Click to scroll </button> 
      </>
   )
}
Ozumah Ebenezer Ikechukwu

reaccionar cómo desplazarse al elemento

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. 

}
Graceful Grasshopper

Respuestas similares a “desplazarse a la sección Reaccionar”

Preguntas similares a “desplazarse a la sección Reaccionar”

Más respuestas relacionadas con “desplazarse a la sección Reaccionar” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código