jQuery(document).ready(function($) { if ($("#onepagemenu").length) { var outerHeight = $("body").outerHeight(); var scrollHeight = $('body')[0].scrollHeight; if (outerHeight < scrollHeight) { $("#onepagemenu").removeClass("hideit"); //$("#menumobilebtn").removeClass("hideit"); } else { $("#onepagemenu").addClass("hideit"); //$("#menumobilebtn").addClass("hideit"); } var one = ''; var two = ''; var three = ''; var four = ''; var five = ''; if ($("#about").length) { one = $("#about"); } else { one = $("#top"); } if ($("#services").length) { two = $("#services"); } else { two = $("#top"); } if ($("#works").length) { three = $("#works"); } else { three = $("#top"); } if ($("#contact").length) { four = $("#contact"); } else { four = $("#top"); } if ($("#details").length) { five = $("#details"); } else { five = $("#top"); } one = one.offset(); two = two.offset(); three = three.offset(); four = four.offset(); five = five.offset(); $(window).on('resize', function(){ one = one.offset(); two = two.offset(); three = three.offset(); four = four.offset(); five = five.offset(); outerHeight = $("body").outerHeight(); scrollHeight = $('body')[0].scrollHeight; if (outerHeight < scrollHeight) { $("#onepagemenu").removeClass("hideit"); //$("#menumobilebtn").removeClass("hideit"); } else { $("#onepagemenu").addClass("hideit"); //$("#menumobilebtn").addClass("hideit"); } }); $(window).scroll(function(){ //the scroll() function will run every time the selected object is scrolled. //since you are binding the change of size to the scroll event, it may be best not to provide a direct //href to the objects. Instead, you may want to use scrollTo inside of a click event. //Or, you could just add a click event that calls scroll when the link is clicked, as done below. //calling the scrollTop() function with no arguments will give you the current position in pixels of the selected object. var screenPosition = $(document).scrollTop(); if (screenPosition < one.top - 200) { $("#menu-item-1").removeClass("active"); $("#menu-item-2").removeClass("active"); $("#menu-item-3").removeClass("active"); $("#menu-item-4").removeClass("active"); $("#menu-item-5").removeClass("active"); } if (screenPosition >= one.top - 200) { $("#menu-item-1").addClass("active"); $("#menu-item-2").removeClass("active"); $("#menu-item-3").removeClass("active"); $("#menu-item-4").removeClass("active"); $("#menu-item-5").removeClass("active"); } if (screenPosition >= two.top - 200) { $("#menu-item-1").removeClass("active"); $("#menu-item-2").addClass("active"); $("#menu-item-3").removeClass("active"); $("#menu-item-4").removeClass("active"); $("#menu-item-5").removeClass("active"); } if (screenPosition >= three.top - 200) { $("#menu-item-1").removeClass("active"); $("#menu-item-2").removeClass("active"); $("#menu-item-3").addClass("active"); $("#menu-item-4").removeClass("active"); $("#menu-item-5").removeClass("active"); } if (screenPosition >= four.top - 200) { $("#menu-item-1").removeClass("active"); $("#menu-item-2").removeClass("active"); $("#menu-item-3").removeClass("active"); $("#menu-item-4").addClass("active"); $("#menu-item-5").removeClass("active"); } if (screenPosition >= five.top - 200) { $("#menu-item-1").removeClass("active"); $("#menu-item-2").removeClass("active"); $("#menu-item-3").removeClass("active"); $("#menu-item-4").removeClass("active"); $("#menu-item-5").addClass("active"); } if($(window).scrollTop() + $(window).height() == $(document).height()) { $("#menu-item-1").removeClass("active"); $("#menu-item-2").removeClass("active"); $("#menu-item-3").removeClass("active"); $("#menu-item-4").removeClass("active"); $("#menu-item-5").addClass("active"); } }); //call the scroll() event so that the proper one is highlighted at the start $(window).scroll(); } }); // to top right away if ( window.location.hash ) scroll(0,0); // void some browsers issue setTimeout( function() { scroll(0,0); }, 1); jQuery(document).ready(function(){ // Add smooth scrolling to all links jQuery('#onepagemenu').on('click', 'a', function(event) { // Make sure this.hash has a value before overriding default behavior if (this.hash !== "") { // Prevent default anchor click behavior event.preventDefault(); // Store hash var hash = this.hash; // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area jQuery('html, body').animate({ scrollTop: jQuery(hash).offset().top }, 800, function(){ // Add hash (#) to URL when done scrolling (default click behavior) window.location.hash = hash; }); } // End if }); // Add smooth scrolling to all links jQuery('#gotosection').on('click', 'a', function(event) { // Make sure this.hash has a value before overriding default behavior if (this.hash !== "") { // Prevent default anchor click behavior event.preventDefault(); // Store hash var hash = this.hash; // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area jQuery('html, body').animate({ scrollTop: jQuery(hash).offset().top }, 800, function(){ // Add hash (#) to URL when done scrolling (default click behavior) window.location.hash = hash; }); } // End if }); });