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

120
Views
Scroll to section in HTML/CSS

if I have the following JS code:

 //Scroll Down button
    $(window).scroll(function () {
    if ($(this).scrollDown() > 100) {
      $('.containerScroll').fadeIn('slow');
    } else {
      $('.containerScroll').fadeOut('slow');
    }
  });

  $('.containerScroll').click(function () {
    $('html, body').animate({
      scrollTop: 0
    }, 1500, 'easeInOutExpo');
    return false;
  });

This basically is for the Back-top-button animation where if the user clicks the button, then it brings the user back to the homepage with smooth scrolling. I would like the opposite. Is there a way to modify the above JS code so that when the user clicks the button, it brings the user to whichever page they desire? Right now, this scrolls all the way to the top and brings the user to only the homepage of the website, but how can I make it so it would bring the user to whichever page on the website?

This is what I have in HTML file:

<a href="#about" class="containerScroll">
      <div class="first-scroll"></div>
      <div class="second-scroll"></div>
      </a>

Basically, I would like the user to go in the about section of the page instead of the homepage. Any suggestions on how to achieve this task?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can set the scrollTop value to the offset of whatever element you want. For example:

$('html, body').scrollTop($('#about').offset().top);

will set scrollTop to the top of the element with id about by getting its offset.

Or you could use animate as you did in your example:

$('html, body').animate({
    'scrollTop': $('#about').offset().top
}, 1500);

Fiddle

Fiddle smooth scroll

about 4 years ago · Juan Pablo Isaza Report

0

to top

window.scrollTo({
  top: 0,
  behavior: 'smooth'
});

to element

const element = getElementById("someElement");
//you can do it by jquery. no matter
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});

MDM: scrolIntoView

MDM: scrollTo

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!