This seems to be it. This is only being applied to ‘wheel’ events here. The basic idea is that if you are scrolling with the mousewheel in the menu-panel, when you have scrolled to either the bottom or the top of the panel, stop the event and don’t let it bubble up to the window. This is tested on Chrome, Safari, and Firefox 17 on a mac. I guess it needs to be debounced - and removed in ‘willDestroyElement’.
// menu-panel.js.es6
...
@on('didInsertElement')
_bindEvents() {
...
this.$().on('DOMMouseScroll wheel', (e) => {
let scrollTop = $('.panel-body').scrollTop();
// Total height of the menu content
let scrollHeight = $('.panel-body-contents')[0].scrollHeight;
// Inner height of menu-panel - not including padding
let height = this.$().height();
// Amount and direction of pagescroll movement. 'DOMMouseScroll' is for Firefox
let delta = parseInt((e.type === 'DOMMouseScroll' ? e.originalEvent.detail * 40 : e.originalEvent.deltaY), 10);
// Not necessary but makes it easier to understand for now.
let scrollDir = delta < 0 ? 'up' : 'down';
let _prevent = () => {
e.stopPropagation(); // Don't bubble up
e.preventDefault(); // Don't perform the action
};
// Only apply this if there is scrollable content in the menu.
// This test fails on menu-panel.slide-in when the menu-panel height is between 0 and 16px less than the scrollHeight - that is fixable.
if (scrollHeight > height) {
// Stop the action and scroll to the bottom of the content if the mousewheel movement
// is going to take us below the bottom of the content.
if (scrollDir === 'down' && delta > scrollHeight - (height + scrollTop)) {
$('.panel-body').scrollTop(scrollHeight - height);
return _prevent();
// Stop the action and take us to the top of the content if the mousewheel movement is
// going to take us above the top of the content.
} else if (scrollDir === 'up' && -delta > scrollTop) {
$('.panel-body').scrollTop(0);
return _prevent();
}
}
});