Hi,
we customized our navbar so that it docks/shrinks after the user scrolls past a certain point in the page (to achieve docking efftect).
This done via Customizer->JS by adding/removing a “.docked” class to the x-navbar.
Through CSS it changes the height from 90px to 65px.
Our navbar only floats and docks when in Desktop, In Mobile it is only visible at the top of the page.
We were able to override the default scroll behaviour with this line in Customizer->JS:
$('.menu-item > a[href*="#"], .scroll-link').unbind('touchend click');
And added the following code in Customizer->JS which is based on the old x-body.js file with slight modifications to evaluate the navbar height on every event and not just once.
var navbar_height = 91;
var docked_navbar_height = 65;
jQuery(function($) {
var $body = $('body');
var adminbarHeight = $('#wpadminbar').outerHeight();
var locHash = null;
var dragging = false;
var locHashIndex = location.href.indexOf('#');
if ( -1 !== locHashIndex ) {
locHash = location.href.substr(locHashIndex).split('/')[0];
}
$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 ) {
if ( ! element ) {
return;
}
try {
var $el = $(element);
} catch(error) {
// abort on invalid selectors. see #610
return;
}
if ( ! $el || 0 == $el.length ) {
return;
}
var navbarFixedTopHeight = 0;
if($(window).width() >= 979) {
navbarFixedTopHeight = $el.offset().top <= $(window).height()-navbar_height ? navbar_height : docked_navbar_height;
}
$('html, body').animate({
scrollTop: $el.offset().top - adminbarHeight - navbarFixedTopHeight + 1
}, ms, easing);
}
//
// Page load offset (if necessary).
//
$(window).on('load', function() {
animateOffset(locHash, 1, 'linear');
});
//
// Scroll trigger.
//
$('.menu-item > a[href*="#"], .scroll-link').unbind('touchend click');
$('.menu-item > a[href*="#"], .scroll-link').on('touchend click', function(e) {
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');
}
}
});
});
However, with the recent update of X we are no longer able to unbind the X’s default scroll to behaviour (which considers that the navbar height is always at 90px).
Would it be possible to either:
Unbind the default scroll behavior so we use our own code for scroll links…
Or
Use the new X Theme code but somehow be able to consider the change in navbar height.
Thank you.