Guest User

Untitled

a guest
Oct 15th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //On Page Load
  2.  
  3. initReturnToTop();
  4.  
  5. //Functions below
  6.  
  7. function initReturnToTop() {
  8.     //setup our html
  9.     var returnDiv = '\
  10.         <div id="ReturnToTop" style="position:fixed; cursor:pointer; color:#0096ff; font-size:0.7em; background-color:#171717; -moz-border-bottom-left-radius: 13px; border-bottom-left-radius: 13px; -moz-border-bottom-right-radius: 13px; border-bottom-right-radius: 13px; border:2px solid #2b2b2b; padding:2px; padding-left:10px; padding-right:10px; z-index:1000; top:-10px; right:0px;">RETURN TO TOP</div>\
  11.     ';
  12.    
  13.     $('body').prepend(returnDiv);
  14.    
  15.     //hook into scroll and resize events
  16.     $(window).scroll(function () {
  17.         processReturnToTop();
  18.     });    
  19.     $( window ).resize(function() {
  20.         processReturnToTop();
  21.     });
  22.    
  23.     //setup a click handler
  24.     $('#ReturnToTop').click(function(){
  25.        $("html, body").animate({ scrollTop: 0 }, 300);
  26.     });
  27.    
  28.     //run the sub-routine manually once at page load
  29.     processReturnToTop();
  30. }
  31.  
  32. function processReturnToTop() {
  33.     var threshold = 300; //The higher the number, the further down the page the widget rolls in
  34.     var curOffset = $(document).scrollTop();
  35.     if (curOffset > threshold) {
  36.         $('#ReturnToTop').animate({
  37.             'top':parseInt($('#pvpnet-bar').height()) + 'px',
  38.         },500);
  39.     } else {
  40.         $('#ReturnToTop').stop(true).animate({
  41.             'top':0,
  42.         },500);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment