I’d like to make the browser to scroll the page to a given anchor, just by using JavaScript.
I have specified a name or id attribute in my
name
id
This works:
$('.scroll').on("click", function(e) { e.preventDefault(); var dest = $(this).attr("href"); $("html, body").animate({ 'scrollTop': $(dest).offset().top }, 2000); });
https://jsfiddle.net/68pnkfgd/
Just add the class 'scroll' to any links you wish to animate