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

107
Vistas
JQuery use .offset to scroll down to CSS class + extra pixels

I've got a simple jQuery if statement that immediately scrolls down to a section with the class 'registration' once the page is loaded. That works, but I need it to have it go another 156px more due to the sticky header. Otherwise, the top portion of the section won't be visible.

Page in question: https://acumedstaging.wpengine.com/registration

This is what I currently have:

if(top.location.pathname === '/registration/'){
 $('html,body').animate({
   scrollTop: $(".registration").offset({ top: 156 })
 });
}

I've tried some other methods with .offset as well but no luck so far. Any idea how to make this function.... function?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This isn't the correct way to use .offset(), what this code is actually trying to do is set the offset of the elements matched by .registration:

$(".registration").offset({ top: 156 })

.offset() with no arguments returns an object which looks like {top: 400, left: 25} which represents the offset of the element.

Instead use:

$(".registration").offset().top + 156 + 'px'
about 4 years ago · Juan Pablo Isaza Denunciar
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