Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I auto scroll when clicking on my nav bar to a specific part of my page?

I’d like to know if it’s possible to auto-scroll when I’m clicking on my nav bar title right to a specific part of my page? Is it possible without using jQuery?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Very much possible without the use of Javascript or Jquery. I’ve created a basic version of the behavior you’re looking for. This is possible using ids in your HTML. Please see the example.

a {
  font-size: 10rem;
}

html {
  scroll-behavior: smooth;
}
<div class="container">
      <!-- potential navbar component -->
      <a href="#about">About</a><br>
      <img src="https://dummyimage.com/1500/000/fff&text=I'm+a+dumb+image+simply+for+scroll+behavior.">
      <h1 id="about">About</h1> <!-- goes to this spot of page because of id -->
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<img src="https://dummyimage.com/1500/000/fff&text=I'm+a+dumb+image+simply+for+scroll+behavior.">
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading