kisukedeath

smooth scroll & menu fixed

Feb 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.31 KB | None | 0 0
  1. smooth scroll
  2.  
  3. $('a[href*="#"]:not([href="#"])').click(function() {
  4.     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  5.       var target = $(this.hash);
  6.       target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  7.       if (target.length) {
  8.         $('html, body').animate({
  9.           scrollTop: target.offset().top
  10.         }, 1000);
  11.         return false;
  12.       }
  13.     }
  14.   });
  15.  
  16.  
  17. scroll - height menu fixed
  18.  
  19. $('a[href^="#"]:not([href="#"])').on('click',function (e) {
  20.                 e.preventDefault();
  21.  
  22.                 var target = this.hash;
  23.                 var $target = $(target);
  24.  
  25.                 console.log(target);
  26.  
  27.                 if(target == "#produccion"){
  28.                     $('html, body').stop().animate({
  29.                     'scrollTop': $target.offset().top - 65
  30.                     }, 900, 'swing', function () {
  31.                         window.location.hash = target;
  32.                     });  
  33.                 }else{
  34.                    $('html, body').stop().animate({
  35.                     'scrollTop': $target.offset().top - 48
  36.                 }, 900, 'swing', function () {
  37.                     window.location.hash = target;
  38.                 });
  39.                 }
  40.                
  41.             });
Advertisement
Add Comment
Please, Sign In to add comment