Onclick menu button, website scrolls to div

12,189

Solution 1

For something really basic use this:

<a href="#work">Work</a>

or you can try jQuery plugin ScrollTo

Working Fiddle

Solution 2

If your Work section have a id, for instance work you can do it with:

$('html, body').animate({scrollTop: $("#work").offset().top}, 2000);

with some smooth animation

Share:
12,189
Admin
Author by

Admin

Updated on June 16, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm making a personal portfolio in an infinte scroll website. Right now I have 4 divs (home, bio, work and contact). I have an header with a menu with 4 names, same as divs. So what I want to do is to have a trigger when I'm at the div "Home" and click on the menu "Work" I want the browser to scroll down to the third div whick is "Work". Hope I make myself clear :)

  • Admin
    Admin about 10 years
    that code just opens a blank page. About the ScrollTo plugin, I have no clue how to use it.
  • Jatin
    Jatin about 10 years
    it doesn't open a blank page. It scrolls down to that page.
  • Jatin
    Jatin about 10 years
    For complete example You can hav a look at insitedesignlab.com/how-to-make-a-single-page-website
  • Admin
    Admin about 10 years
    It's working thank you, I'm new so, I messed up with the tags, now I just need an animation.
  • Admin
    Admin about 10 years
    Where do I paste this?!
  • Jatin
    Jatin about 10 years
    Glad that i could help you.
  • Admin
    Admin about 10 years
    do you know how to make the animation that pna posted?
  • Jatin
    Jatin about 10 years
    Are you talking about smooth scroll if yes then refer insitedesignlab.com/how-to-make-a-single-page-website
  • Jatin
    Jatin over 9 years
    Thats Nice...All Good Np :)