Return to Snippet

Revision: 33470
at October 9, 2010 00:30 by vagrantradio


Initial Code
$(function(){
/* set variables locally for increased performance */
	var scroll_timer, 
		displayed = false,
		$message = $('#message a'),
		$window = $(window),
		top = $(document.body).children(0).position().top;
 
	/* react to scroll event on window */
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () { // use a timer for performance
			if($window.scrollTop() <= top) // hide if at the top of the page
			{
				displayed = false;
				$message.fadeOut(500);
			}
			else if(displayed == false) // show if scrolling down
			{
				displayed = true;
				$message.stop(true, true).show().click(function () { $message.fadeOut(500); });
			}
		}, 100);
	});
});

Initial URL
http://briancray.com/2009/10/06/scroll-to-top-link-jquery-css/

Initial Description
Courtesy Brian Cray.

Initial Title
jQuery Disappearing Back-to-Top Link

Initial Tags
jquery

Initial Language
jQuery