(function($) { "use strict"; $(document).ready(function() { $(this).scrollTop(0); }); // Back to top button $(window).scroll(function() { if ($(this).scrollTop() > 100) { $(".back-to-top").fadeIn("slow"); } else { $(".back-to-top").fadeOut("slow"); } }); $(".back-to-top").click(function() { $("html, body").animate({ scrollTop: 0 }, 1500, "easeInOutExpo"); return false; }); var selectedIndex = null; $(".workArea-item").click(function() { $(".workArea-item").removeClass("active-item"); if (selectedIndex !== $(this).index()) { $(this).addClass("active-item"); selectedIndex = $(this).index(); } else { selectedIndex = null; } return false; }); var listGroupSelectedIndex = null; $(".list-group-item").click(function(e) { if($(e.target).is(".btn") || $(e.target).is("a[target=_blank]")) return true; $(".list-group-item").parent().removeClass("active-item"); if (listGroupSelectedIndex !== $(this).parent().index()) { $(this).parent().addClass("active-item"); listGroupSelectedIndex = $(this).parent().index(); } else { listGroupSelectedIndex = null; } return false; }); // Initiate the wowjs animation library new WOW().init(); // check if click any nav items var isNavItemSelected = false; // Smooth scroll for the navigation and links with .scrollto classes $(".nav a, .scrollto").on("click", function() { if ( location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") && location.hostname == this.hostname ) { var target = $(this.hash); if (target.length) { var top_space = 0; if ($("#header").length) { top_space = $("#header").outerHeight() + 40; //add extra 40 for more padding } $("html, body").animate( { scrollTop: target.offset().top - top_space }, 1500, "easeInOutExpo" ); if ($(this).parents(".nav").length) { $(".nav .active").removeClass("active"); $(this) .closest("li") .addClass("active"); isNavItemSelected = true; } return false; } } }); // Navigation active state on scroll var nav_sections = $("section"); var main_nav = $(".nav"); var main_nav_height = $("#header").outerHeight() + 40; //add extra 20 for more padding $(window).on("scroll", function() { var cur_pos = $(this).scrollTop(); nav_sections.each(function() { var top = parseInt($(this).offset().top - main_nav_height); var bottom = parseInt(top + $(this).outerHeight()); if (cur_pos >= top && cur_pos <= bottom && !isNavItemSelected) { main_nav.find("li").removeClass("active"); main_nav .find('a[href="#' + $(this).attr("id") + '"]') .parent("li") .addClass("active"); } if (cur_pos == top) { isNavItemSelected = false; } }); }); })(jQuery);