Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda