$(window).scroll(function(){ var window_top = $(window).scrollTop() + 1; if (window_top > 600) { $('.sub-content').addClass('fixed animated fadeInDown'); } else { $('.sub-content').removeClass('fixed animated fadeInDown'); } }); var subTop=$('.sub-content .sub').offset().top $('.sub-content .sub a').on('click' , function(e){ $('.sub-content .sub a').removeClass('on'); $(this).parent().addClass('on'); var target = $('[data-scroll='+$(this).attr('href')+']'); e.preventDefault(); //console.log(subTop+' | '+ $(window).scrollTop()) var sj_w=0 if($(window).width()<1199){ sj_w=$('.header').height()+$('.sub-content .sub').height()+6 }else{ sj_w=$('.header').height()-10 } //console.log(sj_w+'_sj_w') if($(window).scrollTop()= 0) { $('[data-scroll]').each(function(i) { var num = $(this).position().top var fd=0 if($(window).width()<1199){ fd=130 }else{ fd=80 } if ($(this).offset().top <= windscroll + fd) { target.removeClass('on'); target.eq(i).addClass('on'); var num = $(this).position().top var cls = $(this).attr("class") } }); }else{ target.removeClass('on'); $('.sub-content .sub a:first').addClass('on'); } });