I am encountering an issue on my webpage where I have a fixed y scrollable sidenav and a main body. The problem arises when scrolling with the mouse wheel while the pointer is inside the side nav, causing the body to scroll depending on the element's position. This issue is due to the margin of the main body still overlapping with the side nav because of Bootstrap offset such as offset-md-3
.
https://i.sstatic.net/svXqe.png https://i.sstatic.net/imWAT.png
I am seeking a solution to prevent the main body from scrolling when the mouse is on the sidenav without using any plugins. I specifically require a solution using jQuery and Bootstrap 4 only.
Initially, I thought of fixing the issue like this, but changing to fixed caused the main body to snap back to the top.
I tried disabling scrolling on hover over the .SideNav
, but I needed to keep the scrollbar for consistency.
$(".SideNav").hover(function () {
$('body').css({
"position": 'fixed',
"overflow-y": 'scroll'
});
},
function () {
$('body').css({
position: 'inherit',
"overflow-y": 'scroll'
});
});