Javascript 允许滚动但隐藏滚动条

Javascript 允许滚动但隐藏滚动条,javascript,html,css,Javascript,Html,Css,我有一个div,元素样式如下: <div style="overflow-y: auto; max-height: 300px;">< id="DivTableContainer" ></div> 虽然它隐藏了滚动条,但也不允许滚动。有没有一种方法可以在不显示滚动条的情况下进行滚动?试试以下方法: HTML: <div id="container"> <div id="content"> // Content

我有一个
div
,元素样式如下:

 <div style="overflow-y: auto; max-height: 300px;">< id="DivTableContainer" ></div>
虽然它隐藏了滚动条,但也不允许滚动。有没有一种方法可以在不显示滚动条的情况下进行滚动?

试试以下方法:

HTML:

<div id="container">
    <div id="content">
        // Content here
    </div>
</div>
#container{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

#content{
    width: 100%;
    height: 99%;
    overflow: auto;
    padding-right: 15px;
}

html, body{
    height: 99%;
    overflow:hidden;
}
<div id="container1">
    <div id="container2">
        // Content here
    </div>
</div>
 #container1{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

 #container2{
    height: 100%;
    width: 100%;
    overflow: auto;
    padding-right: 20px;
}


在FF和Safari上测试。

如果在HTML中使用两个div容器,效果会更好

如下图所示:

HTML:

<div id="container">
    <div id="content">
        // Content here
    </div>
</div>
#container{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

#content{
    width: 100%;
    height: 99%;
    overflow: auto;
    padding-right: 15px;
}

html, body{
    height: 99%;
    overflow:hidden;
}
<div id="container1">
    <div id="container2">
        // Content here
    </div>
</div>
 #container1{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

 #container2{
    height: 100%;
    width: 100%;
    overflow: auto;
    padding-right: 20px;
}

我知道这是一个古老的,但这里有一个快速的方法隐藏纯CSS滚动条

加上

::-webkit-scrollbar {display:none;}
您正在使用滚动条的div的id或class


这里有一个有用的链接

Try,当你悬停时它会显示滚动条。嗨@Jake745。我编辑了你的问题,因为它以前是不可理解的。你能检查一下它是否仍然问你想问的问题吗?如果没有,请留下评论或自己编辑:)。干得好,乔纳斯。谢谢你的支持:)好主意,亲爱的。。。那么,你要接受答案,然后拒绝它吗?但的副本在Firefox上不起作用;)正确,Firefox没有::webkit。。您必须使用一些javascript或jquery来隐藏它,或者尝试使用一些css来设置它的样式。