Skip to content

Instantly share code, notes, and snippets.

@DevShahidul
Created December 12, 2018 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevShahidul/89dc5bbc8abea1ff4862a6f9ee7ba247 to your computer and use it in GitHub Desktop.
Save DevShahidul/89dc5bbc8abea1ff4862a6f9ee7ba247 to your computer and use it in GitHub Desktop.
//Navigation function
var sections = $('.section-parent'),
nav = $('nav.main-nav');
//nav_height = $('.main-header-section').outerHeight();
$(window).on('scroll', function (){
var cur_pos = $(this).scrollTop();
sections.each(function () {
var top = $(this).offset().top - 5,
bottom = top + $(this).outerHeight();
if (cur_pos >= top && cur_pos <= bottom) {
nav.find('a').parent().removeClass('active');
sections.removeClass('active');
$(this).addClass('active');
nav.find('a[href="' + $(this).attr('id') + '"]').parent().addClass('active');
sectionBg = $(this).find(".section-bg").attr('src');
$("#hero-wrap").css({
"background-image" : "url(" + sectionBg + ")"
})
}
});
});
$(".main-nav ul li a").each(function(){
var id = $(this).attr('href');
$(this).addClass(id+'-link');
})
nav.find('a').on('click', function () {
var $el = $(this),
id = $el.attr('href');
$(".main-nav ul li").removeClass('active');
$el.parent().addClass('active');
$('html, body').animate({
scrollTop: $('#'+id).offset().top - 0
}, 1000, 'easeInOutCubic');
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment