jQuery(window).scroll(function(){ if (jQuery(this).scrollTop() > 170) { //console.log(jQuery(this).scrollTop()); jQuery('.header,#header-main').addClass('fixed-header'); } else { jQuery('.header,#header-main').removeClass('fixed-header'); } }); jQuery(document).ready(function(){ jQuery('.header-container a[href^="#"],a[href^="#"]').on('click',function (e) { e.preventDefault(); var target = this.hash; $target = jQuery(target); jQuery('html, body').stop().animate({ 'scrollTop': $target.offset().top }, 900, 'swing', function () { window.location.hash = target; }); }); });