I guess you are trying the below solution. If you have custom Navbar and id hardcoded, this might work.
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_navbar_hide_scroll
But if you are mendix top-bar navigation, you can use getElementByClassName(‘region-topbar’) would solve the problem. Also you need to change the CSS from #navbar to .region-topbar