First a big thank you for such a wonderful module. It never ceases to amaze me how generous Drupal developers can be with their time and effort. It's greatly appreciated.
I am working on a Drupal 7 project and have successfully integrated the responsive menu. I'm using it with a bootstrap based theme and have experienced and corrected only a few issues thus far.
I have the Superfish menu and off-canvas menu icon contained in a fixed positioned menu bar that remains at the top of the page. However, I have found that when clicking on the menu icon that triggers the off-canvas menu, the page will first scroll to the top, before the off-canvas menu is displayed. This happens on Android as well as on a PC and Mac. I do not have the HTML or BODY elements set with a 100% width or height, and I am not seeing any script errors in my console (everything works great). It's as if the menu icon acts like an anchor tag, as I am seeing the #off-canvas ID appended to the URL in Chrome and Android.
I am not certain if this is the standard behavior. However, it is most noticeable on mobile devices due to the lag between the page scrolling, then the off-canvas menu opening. In reviewing the demos on the mmenu website, I am not seeing pages scroll before the menu is triggered. However, I am not certain if this is the implementation of the Drupal module. I am seeing that the implementation on the mmenu website uses e.preventDefault():
var $burger = $('#hamburger')
.on( 'click',
function( e )
{
e.preventDefault();
if ( $html.hasClass( 'mm-opened' ) )
{
API.close();
}
else
{
API.open();
}
}
)
.children( '.hamburger' );
API.bind( 'closed', function() {
setTimeout(function() {
$burger.removeClass( 'is-active' );
}, 100);
});
API.bind( 'opened', function() {
setTimeout(function() {
$burger.addClass( 'is-active' );
}, 100);
});Any suggestions for how to prevent the page scrolling before the menu opens would be greatly appreciated. Thank you again for the time spent on this fantastic module.
Comments
Comment #2
tancSorry for the lack of response on this. I suspect the jump is due to the href on the toggle icon. I think it would be sensible to preventDefault on the link.
Comment #3
tancI don't think this is an issue anymore with the latest version of the module and mmenu library. At least I couldn't replicate it, so closing as outdated.