$(function(){ var backbutton = $('#btn-back-to-top'); backbutton.hide(); $(window).scroll(function () { if ($(this).scrollTop() > 100) { backbutton.fadeIn(); } else { backbutton.fadeOut(); } }); backbutton.click(function () { $('body, html').animate({ scrollTop: 0 }, 500); return false; }); });