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

172
Views
¿Cómo configurar un desplazamiento suave a mi barra de navegación JS?

He codificado una barra de navegación usando JS, necesito agregar un desplazamiento suave activo cuando un usuario hace clic en una de las secciones escritas en JS puro (y no en el desplazamiento suave de CSS) Estaba pensando en algo con scrollIntoView o scrollTo pero cada vez que codifico hace que la barra de navegación desaparezca o no funcione en absoluto. Aquí está mi código de barra de navegación. Cualquier ayuda es apreciada.

 function navBar() { const section = document.getElementsByTagName('section'); for (let i = 0; i < section.length; i++) { let navBarUL = document.getElementById("navBarULID"); let link = `<a href='#' onclick="console.log(${i})" id='link_no${i+1}'> Section ${i+1} </a>`; let newLI = document.createElement("li") newLI.innerHTML = link navBarUL.appendChild(newLI) let j = i } for (let i = 0; i < section.length; i++) { document.getElementById( 'link_no' + (i + 1)).addEventListener('click', function(e) { e.preventDefault(); let allActiveLinks = document.getElementsByClassName('active-link'); for (let i = 0; i < allActiveLinks.length; i++) { const element = allActiveLinks[i]; element.classList.remove('active-link'); }

Aquí hay una muestra de HTML

 <ul id="navBarULID"></ul> </nav> </header> <main> <header class="main__hero"> <h1 id="p1">Landing Page </h1> </header> <section id="section1" class="your-active-class"> <div class="landing__container"> <h2 id="section1ID">Section 1</h2> <p>test.</p> </div> </section> <section id="section2" > <div class="landing__container"> <h2 id="section2ID">Section 2</h2> <p>test.</p> </div> </section> <section id="section3" > <div class="landing__container"> <h2 id="section3ID">Section 3</h2> <p>test.</p> </div> </section>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

usa este código CSS

 html { scroll-behavior: smooth; }
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!