yan-k
11/14/2014 - 12:39 PM

jQuery scroll to top

jQuery scroll to top

$(function() {

	//Check to see if the window is top if not then display button
	$(window).scroll( function() {
		if ($(this).scrollTop() > 100) {
			$('#scroll-top').fadeIn();
		} else {
			$('#scroll-top').fadeOut();
		}
	});
	
	//Click event to scroll to top
	$('#scroll-top').click(function(){
		$('html, body').animate( { scrollTop : 0 }, 450);
		return false;
	});
	
});