This is an old question, but it may still be useful for others, I wanted to implement the scroll function to the top in one of my projects with sharepoint.
After breaking my head for about a few hours. I got it with the code below.
Actually $(window).scroll() does not start at a common point, I use the main identifier there, which ('#s4-workspace') , to make it work.
$(document).ready(function () { var offset = 220; var duration = 1000; jQuery('#s4-workspace').scroll(function() { if (jQuery(this).scrollTop() > offset) { jQuery('.arrowToTop').fadeIn(duration); } else { jQuery('.arrowToTop').fadeOut(duration); } }); jQuery('.arrowToTop a').click(function(event) { event.preventDefault(); jQuery('#s4-workspace').animate({scrollTop: 0}, duration); return false; }) });
I used below CSS style
.arrowToTop { display: none; height: 100%; position: fixed; right: 20px; z-index: 9999; bottom: 0; width: 70px; height:70px; } .arrowToTop a{ width: 70px; height:70px; display: block; background: url(../images/arrow.png) no-repeat left 0; }
source share