i know this thread is old, but i’ve bumped into the same problem as llribas today (11 oct 2019, pro 7.0.4).
i played about with the above JS a little, and discovered that jquery has changed the easing options in the interim which is why it didn’t work (at all) for me. changing line 62 got things working:
animateOffset($el, 850, ‘xEaseInOutExpo’);
notice the added ‘x’ in ‘xEaseInOutExpo’
i also found that my ‘navbarFixedTopHeight’ selector needs to be ‘.masthead’ to correctly determine the offset.
here’s the full code for copy-n-paste:
jQuery(document).ready(function($) {
var $body = $('body');
var bodyHeight = $body.outerHeight();
var adminbarHeight = $('#wpadminbar').outerHeight();
var navbarFixedTopHeight = $('.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($('.hm1.x-bar-fixed').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');
}
}
});
});