1

我在以下代码中缺少什么?为什么完美滚动条可怕地崩溃?

似乎它用浏览器主滚动条弄乱了 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>

谢谢

4

1 回答 1

5

添加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

容器必须具有“位置”css 样式。

于 2016-08-29T16:05:18.040 回答