Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable scroll on sidenav

Tags:

css

i want to ask

i have a show hide menu (openNav, closeNav)

this my javascript :

function openNav() {
    document.getElementById("mySidenav").style.width = "100%";
    // document.getElementById("flipkart-navbar").style.width = "50%";
    document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
    document.body.style.backgroundColor = "rgba(0,0,0,0)";
}

and this my css script :

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #fff;
    overflow-x: hidden;
    transition: 0.5s;
    box-shadow: 0 4px 8px -3px #555454;
    padding-top: 0px;
}

i try to add overflow-y: hidden; but not work

i try to change the overflow:visible or auto not work to

i try to change the position to absolute or relative not work to sir

the scroll still show

this my screenshoot :

enter image description here

see the scroll bar from my screenshoot, the scroll bar show not hide or disable

how to hide or disable the scrollbar sir?

thanks before

like image 547
user3075428 Avatar asked Oct 15 '25 05:10

user3075428


2 Answers

you need to target the overflow body element in js. Below is the code:

function openNav() {
    document.getElementById("mySidenav").style.width = "100%";
    // document.getElementById("flipkart-navbar").style.width = "50%";
    document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
    document.body.style.overflow = "hidden";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
    document.body.style.backgroundColor = "rgba(0,0,0,0)";
    document.body.style.overflow = "auto";
}
like image 106
Rakesh Avatar answered Oct 16 '25 20:10

Rakesh


Try

overflow: hidden;
height:100vh;
width: 100vh;
like image 23
Bhautik Chudasama Avatar answered Oct 16 '25 20:10

Bhautik Chudasama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!