icorrelate

Scroll To Top

May 23rd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.99 KB | None | 0 0
  1. <!-- Make sure you include JQUERY!! -->
  2.  
  3. <style>
  4.         .back-to-top {
  5.             position: fixed;
  6.             bottom: 2em;
  7.             right: 0px;
  8.             text-decoration: none !important;  
  9.             color: #000000;
  10.             background-color: rgba(235, 235, 235, 0.80);
  11.             font-size: 12px;
  12.             padding: 1em;
  13.             display: none; 
  14.         }
  15.  
  16.         .back-to-top:hover {   
  17.             background-color: rgba(135, 135, 135, 0.50);
  18.         }
  19. </style>
  20.  
  21. <!-- Place this at the bottom of your page -->
  22. <a href="#" class="back-to-top">Back to Top</a>
  23.  
  24.     <script>            
  25.             jQuery(document).ready(function() {
  26.                 var offset = 220;
  27.                 var duration = 500;
  28.                 jQuery(window).scroll(function() {
  29.                     if (jQuery(this).scrollTop() > offset) {
  30.                         jQuery('.back-to-top').fadeIn(duration);
  31.                     } else {
  32.                         jQuery('.back-to-top').fadeOut(duration);
  33.                     }
  34.                 });
  35.                
  36.                 jQuery('.back-to-top').click(function(event) {
  37.                     event.preventDefault();
  38.                     jQuery('html, body').animate({scrollTop: 0}, duration);
  39.                     return false;
  40.                 })
  41.             });
  42.         </script>
Add Comment
Please, Sign In to add comment