Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

104
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda