You need to have in the menu some indication of the target for the scroll.
Can be id
of element saved in a data
property, one href / anchor, or another. If you use an anchor ( <a>
) you may need to use .preventDefault()
to prevent the link from being followed (in some cases you even want the link to be in the url, then you should not use).
After you have to intercept the click, you can use the jquery .anymate () to scroll, and get the position of that element as a target.
HTML example
<div class="menu">
<div data-destino="parte1">Parte 1</div>
<div data-destino="parte2">Parte 2</div>
</div>
<div id="parte1"></div>
<div id="parte2"></div>
Example of jQuery
$('.menu div').on('click', function () {
var destino = '#' + $(this).data('destino');
var posicaoDestino = $(destino).position().top;
$('html, body').stop().animate({
scrollTop: posicaoDestino
}, 2000);
});
Example: link