$(document).ready(function () {
$(document).on("scroll", onScroll); $('.tab-content a[href*="#"]').on('click', function (e) { e.preventDefault(); $(document).off("scroll"); $('a').each(function () { $(this).removeClass('active'); }); $(this).addClass('active'); var target = this.hash, $target = $(target); $('html, body').stop().animate({ 'scrollTop': $target.offset().top+2 }, 500, 'swing', function () { window.location.hash = target; $(document).on("scroll", onScroll); }); });
});
function onScroll(event){
var scrollPos = $(document).scrollTop(); $('.tab-content a').each(function () { var currLink = $(this); var refElement = $(currLink.attr("href")); if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
$('.tab-content a').each(function(){
let self = this; $(this).removeClass("active"); $(this).on('click',function(){ $(self).addClass('active'); });
});
currLink.addClass("active"); } else{ currLink.removeClass("active"); } });
}