我需要这个函数来启用垂直滚动,但不是水平滚动。
这不起作用:
function scrollFunction() {
// Scroll to top
document.getElementsByTagName('body')[0].style.overflow-y='auto';
}
虽然这样做了,但它支持垂直和水平滚动。
function scrollFunction() {
// Scroll to top
document.getElementsByTagName('body')[0].style
HTML代码
<p>overflow:auto</p>
<div class="auto">This adds the scroll bar based on you content.Here only vertical scroll bar needed so that is added n visible</div>
CSS代码
div.auto
{
background-color:#00FF00;
width:100px;
height:100px;
overflow:auto;
}
输出
用overflow-y:auto
用overflow-y:scroll
如果滚动条溢出(而不是隐藏内容),是否有办法使其具有滚动条,但如果它不溢出,则同时删除它吗?
目前的css:
max-height: 400px;
overflow-y: scroll;
overflow-x: hidden; <-- do not want horizontal scroll under any circumstances, want the div to respond to the content
Meteor在iphones上的流畅滚动有一个奇怪的问题:
通过添加此CSS代码片段,可以轻松修复此问题
html, body {
overflow-y: scroll; /* has to be scroll, not auto */
-webkit-overflow-scrolling: touch;
}
但是,一旦添加了overflow:
overflow-y: scroll; /* has to be scroll, not auto */
然后javascript scrollTo就不再起作用了,我用它和react-router一起滚动到路由更改的顶部:
const sc