我有这段代码可以在桌面浏览器上运行。我怎样才能在移动浏览器上实现这种行为?基本上我想创建一个将滚动到两侧的菜单。
<style type="text/css">
#navBar {
height: 55px;
width: 80px;
overflow-x: scroll;
overflow-y:hidden;
white-space: nowrap;
}
#navBar div {
display: inline-block;
}
</style>
<div id="navBar">
akdhbaIDBhbfbhwhfbaibf
<div style="width: 100px; text-align: center; background-color: red;">
<img src="" alt="Nav1" />
<br />
<span style="font-size: 80%">Nav1</span>
</div>
<div style=" width: 100px; text-align: center;">
<img src="" alt="Nav2" />
<br />
<span style="font-size: 80%">Nav2</span>
</div>
<div style=" width: 100px; text-align: center; background-color: red;">
<img src="" alt="Nav3" />
<br />
<span style="font-size: 80%">Nav3</span>
</div>
</div>
最佳答案
您可以使用 -webkit-overflow-scrolling: touch; 启用原生滚动
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
div {
overflow-y: hidden;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
width: 150px;
border: 1px solid grey;
}
h1 {
width: 400px;
}
</style>
</head>
<body>
<div>
<h1>some content here</h1>
</div>
</body>
</html>
关于javascript - 如何让 div scroll overflow-x 在移动浏览器上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11591321/