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

79
Views
Comportamiento scrollintoview suave interrumpido al presionar la tecla

Estoy diseñando una página de desplazamiento simple. Se divide en una serie de div (o secciones). Al presionar la tecla de flecha hacia abajo o hacia arriba, debe desplazarse a la vista a la sección siguiente o anterior.

El siguiente código parece funcionar si presiono la tecla hacia abajo o hacia arriba una vez por segundo, pero si sigo presionando la tecla, pasa a la siguiente sección, pero se queda atascado en el medio. Es gracioso, porque si cambio el parámetro scrollintoview a {behavior: "auto"}, no hay tal problema.

¿Hay alguna manera de arreglar esto?

 moveToSection(sectionID, sectionY) { document .getElementById(sectionID) .scrollIntoView({ block: "start", behavior: "smooth" }); this.setState({ lastScrollTop: sectionY }); } checkDownCondition() { if (this.state.keyDown) { console.log("key is pressed - returning"); return; } this.setKeyDown(); document.removeEventListener("keydown", this.handleKeyDown); var currentPos = this.state.lastScrollTop; const sectionTwoY = this.state.sectionTwoY; const sectionThreeY = this.state.sectionThreeY; const sectionFourY = this.state.sectionFourY; const sectionFiveY = this.state.sectionFiveY; if (this.state.keyDown) { setTimeout(() => { // scrolling from section1 to section2 if (currentPos < sectionTwoY) { this.moveToSection("section2", sectionTwoY); // scrolling from section2 to section3 } else if (currentPos >= sectionTwoY && currentPos < sectionThreeY) { this.moveToSection("section3", sectionThreeY); // scrolling from section3 to section4 } else if (currentPos >= sectionThreeY && currentPos < sectionFourY) { this.moveToSection("section4", sectionFourY); // scrolling from section4 to section5 } else if (currentPos >= sectionFourY && currentPos < sectionFiveY) { this.moveToSection("section5", sectionFiveY); } }, 1); setTimeout(() => { this.setKeyUp(); document.addEventListener("keydown", this.handleKeyDown); }, 1000); } }
about 4 years ago · Juan Pablo Isaza
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!