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

106
Views
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 answers
Answer question

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 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!