1 $("#scroll_icon").click(function()
2 {
3 jQuery('html,body').animate({scrollTop:0},2000);
4 })
1// Select all »a« elements with a parent tag »nav« and add a function that is executed on click
2$('#id a').on('click', function (e) {
3
4 // Define variable of the clicked »a« element (»this«) and get its href value.
5 var href = $(this).attr('href')
6
7 // Run a scroll animation to the position of the element which has the same id like the href value.
8 $('html, body').animate({
9 scrollTop: $(href).offset().top
10 }, '300')
11
12 // Prevent the browser from showing the attribute name of the clicked link in the address bar
13 e.preventDefault()
14
15})
1
2$(document).ready(function(){
3 $(".scroll-top").click(function() {
4 $("html, body").animate({
5 scrollTop: 0
6 }, "slow");
7 return false;
8 });
9});
10