×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nicole Patten
Added: Dec 2, 2016 8:14 PM
Views: 20
Tags: no tags
  1.   self.backToTopButton = function() {
  2.  
  3.     var $scrollButton = $('.top-link');
  4.  
  5.     $(window).scroll(function(){
  6.       var distanceFromTop = $(window).scrollTop();
  7.       if( distanceFromTop > 100) {
  8.         $scrollButton.fadeIn('fast');
  9.       } else if (distanceFromTop < 1200){
  10.         $scrollButton.fadeOut('fast');
  11.       }
  12.     });
  13.  
  14.     $scrollButton.click(function() {
  15.       $("html, body").animate({ scrollTop: 0 }, "slow");
  16.       return false;
  17.     });
  18.  
  19.   };