javascript - jScrollPane 未显示在 div #container 中

标签 javascript jquery html css jquery-jscrollpane

Fiddle .我正在制作一个杂货 list Web 应用程序,我正在尝试使 div #container 具有 jquery jScrollPane 滚动条。当我添加脚本 src 并添加 $('#container').jScrollPane({showArrows: true}); 时,滚动条没有显示。

HTML(整个正文):

<div id='top'>Kitchen List</div>
<br />
<div id='container'>
<input type='text' id='input'><button id='click'>Add</button>
<ol></ol>
<div id='error'>Please enter a grocery item<br /><button id='eb'>Close</button></div>
</div>

CSS(整个样式):

body {
    margin: 0;
    padding: 0;
    background: #252525;
    color: #96f226
}
#top {
    width: 100%;
    height: 40px;
    background: #96f226;
    text-align: center;
    font-size: 30px;
    color: #252525;
    position: relative;
    position: fixed;
}
#container {
    margin-top: 40px;
}
#input {
    background: #4a4a4a;
    border: 1px solid #454545;
    color: #96f226;
}
#input:hover {
    background: #656565;
}
#input:focus {
    box-shadow: 0 0 30px #96f226
}
#click {
    background: #4a4a4a;
    border: 1px solid #454545;
    border-radius: 0;
    color: #96f226;
    cursor: pointer;
}
#click:hover {
    background: #656565;
}
#click:active {
    box-shadow: 0 0 30px #96f226;
}
#click:focus {
    box-shadow: 0 0 30px #96f226;
}
#error {
    height: 55px;
    width: 100%;
    background: red;
    text-align: center;
    font-size: 23px;
    color: orange;
}
#eb {
    background: orange;
    color: red;
    border-radius: 0;
    border: 0;
    cursor: pointer
}
#eb:hover {
    background: #e59400;
}
#eb:active {
    box-shadow: 0 0 30px #e59400;
}
#check {
    width: 15px;
    height: 15px;
    background: #4a4a4a;
    cursor: pointer
}
#check:hover {
    background: #656565;
}
#check:active {
    box-shadow: 0 0 30px #96f226
}
#check.active {
    background: #96f226
}

JS/JQuery(仅用于滚动条):

$('#container').jScrollPane({showArrows: true});

最佳答案

如果您将以下内容添加到容器的 css 中:

#container {
    margin-top: 40px;
    width: 100%;
    height: 300px;
    overflow: auto;
}

已编辑

您需要使用 data('jsp') 方法创建对 jScrollpane 对象的引用:

var contentPane = $('#container');
contentPane.jScrollPane({showArrows: true});
var api = contentPane.data('jsp');

然后,一旦您添加了新内容,您就可以对 jScrollpane 对象调用 reinitialise() 方法:

api.reinitialise();

Updated Fiddle here .

关于javascript - jScrollPane 未显示在 div #container 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099167/

相关文章:

javascript - onunload 在 Chrome 和 safari 中不起作用

javascript - 如何在 z-index 为 auto 的元素下堆叠?

javascript - 实时检查文本区域的值

html - 为什么 IE 在我的 "modal dialog"后面选择背景中的文本?

javascript - Meteor - 如何在同一模板助手中调用另一个函数

javascript - HTML 5 Canvas : remove color gradient from line edges

javascript - WebPack无法在本地项目中通过命令执行

javascript - Webgl Chrome 空白 Canvas

javascript - jQuery:如何在没有 for 循环的情况下将事件处理程序应用于 $ ('#text' + 'any integer' )?

jquery - 使用回退异步加载 jquery 核心