以下代码中缺少什么? 为什么Perfect scrollbar可怕地崩溃?
似乎它正在用浏览器主滚动条弄乱myDiv滚动条......任何帮助都表示赞赏。
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="utf-8" />
<link href="perfect-scrollbar.min.css" type="text/css" rel="stylesheet">
<style>
#myDiv {
width: 400px;
height: 400px;
overflow: auto;
background-color: #eeeeee;
margin: auto;
}
</style>
</head>
<body>
<div id="myDiv">
<p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p><p>Test perfect scrollbar</p>
</div>
<script type="text/javascript" src="jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="perfect-scrollbar.jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#myDiv').perfectScrollbar();
});
</script>
</body>
</html>
谢谢
答案 0 :(得分:2)
将position:relative
添加到#myDiv
演示:https://jsfiddle.net/gbfLazpx/243/
<强> CSS:强>
#myDiv {
width: 400px;
height: 400px;
overflow: auto;
background-color: #eeeeee;
margin: auto;
position: relative;
}
点击此处的第一点:https://github.com/noraesae/perfect-scrollbar#requirements
容器必须有一个位置&#39; css风格。