Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show "Back to top" link element using jQuery when you scroll down

Tags:

jquery

scroll

I want to mimic behaviour with jQuery like you can see here: http://edo.webmaster.am/

Just look at the right bottom corner, scroll down a bit and you'll see the "back to top" button.

So it's invisible until you scroll down a page and then it appears (animated).

How can I do that in jQuery ?

like image 936
chubbyk Avatar asked May 12 '11 15:05

chubbyk


People also ask

How do you go back to the top in HTML?

Next, add the top of page link using the # symbol and "top" anchor name/id as the value of the href attribute, as shown below. If you scrolled down on this page, clicking this link takes you back to the top of the page. All modern browsers understand the "#top" value.

What is $( window scrollTop ()?

$(selector).scrollTop(position) Parameter. Description. position. Specifies the vertical scrollbar position in pixels.


1 Answers

You can monitor the current window scroll position and act accordingly. If you want the offset to be after a certain point (the below code will do any scrolling, even 1px) then just check that $(this).scrollTop() > n in the if statement, where n is the desired offset.

http://jsfiddle.net/robert/fjXSq/

$(window).scroll(function() {     if ($(this).scrollTop()) {         $('#toTop:hidden').stop(true, true).fadeIn();     } else {         $('#toTop').stop(true, true).fadeOut();     } }); 
like image 73
Robert Avatar answered Sep 22 '22 23:09

Robert