Advertisement
Guest User

Smooth Scrolling

a guest
Mar 4th, 2014
4,808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.92 KB | None | 0 0
  1. //=================================== SMOOTH SCROLLING EXTERNAL ANCHOR //  
  2. (function($){
  3.   $(document).on("ready", function () {
  4.       var urlHash = window.location.href.split("#")[1];
  5.       $('html,body').animate({
  6.           scrollTop: $('.' + urlHash + ', #' + urlHash +',[name='+urlHash+']').first().offset().top -100
  7.       }, 1000);
  8.   });
  9.  
  10. })(jQuery);
  11.  
  12.  
  13. // =================================== SMOOTH SCROLLING LOCAL ANCHOR //
  14. (function($) {
  15.     $('a[href*=#]:not([href=#])').click(function() {
  16.         if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  17.           var target = $(this.hash);
  18.           target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  19.           if (target.length) {
  20.             $('html,body').animate({
  21.               scrollTop: target.offset().top -100
  22.             }, 1000);
  23.             return false;
  24.           }
  25.         }
  26.     });
  27. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement