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

143
Views
jQuery: haga que la función de desplazamiento suave funcione después de cargar la página/navegar a la página

Tengo el siguiente código en nuestro repetitivo que parece funcionar bien en la configuración actual. Se desplaza a la sección de la página cuando hace clic en el enlace del menú de navegación o en un enlace en un control deslizante. Lo que encontré difícil de resolver es hacer que funcione al navegar desde otra página a la página de inicio. Agregará el hash #discover a la URL muy bien, por ejemplo, pero no lo registrará por alguna razón. Ha pasado un tiempo desde que usé correctamente jQuery 😅.

Ya he agregado el estándar en el código listo para documentos alrededor de la función con la esperanza de que sea eso, pero no hay dados. Espero que alguien pueda darme una pista sobre lo que está pasando aquí.

 $(function(){ });
 /* Only enable this when you want smooth scrolling! Usage: - Give the anchor you want to scroll to a certain position a href which starts with # and the class "scroll" (<a href="#container" class="scroll"></a>) - Give the container you want to scroll to a name (<section name="container"></section) - ??? - profit */ const scrollOffset = 0 // the amount of pixels the animation should scroll "extra" (When you have a sticky navigation for example) $(function () { $( '.menu__item a[href*="#"]:not([href="#"]), .slider-list__link[href*="#"]:not([href="#"])' ).click(function () { if ( location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname ) { var target = $(this.hash) target = target.length ? target : $('[name=' + this.hash.slice(1) + ']') $('body').removeClass('no-scroll') $('.navbar').removeClass('navbar--is-open') if (target.length) { setTimeout(() => { // This is used to prevent the animation from the menu closing from interfering with the scrolling animation. It could mess up the offsets otherwise $('html, body').animate( { scrollTop: target.offset().top + scrollOffset, // Scroll to the target }, 400 ) return false }, 500) } } }) })
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!