This topic contains 1 reply, has 1 voice, and was last updated by  Brad 6 months, 1 week ago.

Fixed Smooth Scroll Script

  • There was still an error with the updated smooth scrolling script; it offset the height of the stationary header when it shouldn’t have. This updated code seems to work correctly. Enjoy

    
    $('#header a[href*="#"]:not([href="#"]), #fixed_header a[href*="#"]:not([href="#"]), a.button[href*="#"]:not([href="#"])').click(function() {
    	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
    	      var target = $(this.hash);
    	      target = target.length ? target : $('[id=' + this.hash.slice(1) +']');
    	      if (target.length) {
    	      	$tmp = $('#fixed_header');
    	        if ($.contains(document, $tmp[0])) {
    			    $('html,body').animate({
    		          scrollTop: target.offset().top - ($('#fixed_header').height() + $('#wpadminbar').height())
    		        }, 900);
    			} else {
    				$('html,body').animate({
    		          scrollTop: target.offset().top - $('#wpadminbar').height()
    		        }, 900);
    			}
    	        
    	        return false;
    	      }
    	    }
    	});
    	$(window).load(function(){
    		// Remove the # from the hash, as different browsers may or may not include it
    		var hash = location.hash
    		var myId = hash.split('#');
    		if(hash != ''){
    			$tmp = $('#fixed_header');
    	        if ($.contains(document, $tmp[0])) {
    			    $('html,body').animate({
    		          scrollTop: $('#'+myId[1]).offset().top - ($('#fixed_header').height() + $('#wpadminbar').height())
    		        }, 700);
    			} else {
    				$('html,body').animate({
    		          scrollTop: $('#'+myId[1]).offset().top - $('#wpadminbar').height()
    		        }, 700);
    			}
    		}
    	});
    
    • This topic was modified 6 months, 1 week ago by  Brad.
    • This topic was modified 6 months, 1 week ago by  Brad.
    • This topic was modified 6 months, 1 week ago by  Brad.

    Also, on a side note, pagination seems to interfere with the portfolio page and sorting by filters. If a filtered portfolio item is on the second page and you click the filter in the filter list while on the first page then it doesn’t show the item. You have to actually be on the second page for the item to appear.

You must be logged in to reply to this topic.