// ===== Scroll to Top ==== $(window).scroll(function() { if ($(this).scrollTop() >= 500) { // If page is scrolled more than 50px $('#gotop').fadeIn("25000"); // Fade in the arrow } else { $('#gotop').fadeOut("25000"); // Else fade out the arrow } }); $('#gotop').click(function() { // When arrow is clicked $('body,html').animate({ scrollTop : 0 // Scroll to top of body }, 500); });