Posted By

vagrantradio on 10/09/10


Tagged

jquery


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

sharathreddyp
socheif
bobbym245
Tyster


jQuery Disappearing Back-to-Top Link


 / Published in: jQuery
 

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

Courtesy Brian Cray.

  1. $(function(){
  2. /* set variables locally for increased performance */
  3. var scroll_timer,
  4. displayed = false,
  5. $message = $('#message a'),
  6. $window = $(window),
  7. top = $(document.body).children(0).position().top;
  8.  
  9. /* react to scroll event on window */
  10. $window.scroll(function () {
  11. window.clearTimeout(scroll_timer);
  12. scroll_timer = window.setTimeout(function () { // use a timer for performance
  13. if($window.scrollTop() <= top) // hide if at the top of the page
  14. {
  15. displayed = false;
  16. $message.fadeOut(500);
  17. }
  18. else if(displayed == false) // show if scrolling down
  19. {
  20. displayed = true;
  21. $message.stop(true, true).show().click(function () { $message.fadeOut(500); });
  22. }
  23. }, 100);
  24. });
  25. });

Report this snippet  

You need to login to post a comment.