Scroll anchor doesn't work and console shows thousands of errors

Hi guys!

I just launched a website and my scroll down button doesn’t work. In the first section on this page, there’s a button saying “Få et tilbud” with the href="#kontakt" which is supposed to make the page scroll down to the contact section that has the id=“kontakt”.
http://www.mpentreprise.dk/ydelse/tv-inspektion-af-kloak/

For some reason, it isn’t working :frowning: if i type the url with the anchor it works :tired_face:

Hi there,

Thank you for reaching out to us. The issue you’re having is due to an old JS script you’re using in the Theme Options > JS section. To fix the issue, please replace your code with the following one:

jQuery(document).ready(function($) {
    var $body                = $('body');
    var bodyHeight           = $body.outerHeight();
    var adminbarHeight       = $('#wpadminbar').outerHeight();
    var navbarFixedTopHeight = $('.x-masthead').outerHeight();
    var locHref              = location.href;
    var locHashIndex         = locHref.indexOf('#');
    var locHash              = locHref.substr(locHashIndex);
    var dragging             = false;
    $body.on('touchmove', function() {
    	dragging = true;
    } );
    $body.on('touchstart', function() {
    	dragging = false;
    } );
    //
    // Calculate the offset height for various elements and remove it from
    // the element's top offset so that fixed elements don't cover it up.
    //
    function animateOffset( element, ms, easing ) {
    	$('html, body').animate({
    		scrollTop: $(element).offset().top - adminbarHeight - navbarFixedTopHeight + 1
    		}, ms, easing);
    	}
    //
    // Page load offset (if necessary).
    //
    $(window).load(function() {
    	if ( locHashIndex !== -1 && $(locHash).length ) {
    		animateOffset(locHash, 1, 'linear');
    	}
    });
    //
    // Scroll trigger.
    //
    $('a[href*="#"]').unbind('touchend click').bind('touchend click', function(e) {
    	console.log($('.x-masthead').outerHeight());
    	href        = $(this).attr('href');
    	notComments = href.indexOf('#comments') === -1;
    	if ( href !== '#' && notComments ) {
    		var theId = href.split('#').pop();
    		var $el   = $('#' + theId);
    		if ( $el.length > 0 ) {
    			e.preventDefault();
    			if (dragging) {
    				return;
    			}
    			animateOffset($el, 850, 'xEaseInOutExpo');
    		}
    	}
    });
});

Don’t forget to clear all caches including your browser’s cache after adding the code. Let us know how this goes!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.