Pages

Saturday, January 14, 2017

Smooth Scroll for menu in Onepage site

Smooth Scroll for Onepage site


$(function() {
   $('ul li a[href*="#"]:not([href="#"])').click(function() {
   if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
     var target = $(this.hash);
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
     if($(window).width()>=768){
       if (target.length) {
         $('html, body').animate({
           scrollTop: target.offset().top - 90
         }, 800);
         return false;
       }
     }
     else{
       if (target.length) {
         $('html, body').animate({
           scrollTop: target.offset().top - 50
         }, 800);
         return false;
       }
     }
   }
   });
 });

No comments:

Post a Comment