Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
scrollIntoView() no se desplaza a ninguna parte

No puedo hacer que Element.scrollIntoView() funcione. Tengo el código a continuación. Hay dos ubicaciones a las que debe desplazarse, dependiendo de alguna variable. Sin embargo, no se desplaza a ninguno de ellos. ¿Qué estoy haciendo mal?

 class Page extends Component { scrollToMyRef = (id) => { var ref = document.getElementById(id); console.log("Ref1: " + ref); // returns [object HTMLElement] console.log("Ref2: " + document.ref); // returns undefined console.log("Id: " + id); // returns myRef ref.scrollIntoView({ behavior: "smooth", block: "start", }); }; componentDidMount() { if (this.props.location.state) { if (this.props.location.state.origine) { this.scrollToMyRef("myRef"); } else { this.scrollToMyRef("myTopRef"); }); } } } render() { return ( <div id="myTopRef" key="pricing" className="pricing" > ... </div> <section id=myRef className="section"> ... </section> ... ) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Después de establecer un retraso de tiempo funcionó:

 scrollToMyRef = (id) => { var ref = document.getElementById(id); setTimeout(function () { ref.scrollIntoView({ behavior: "smooth", block: "start", }); }, 100); };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!