无法动态加载 jScrollPane 内容?
当新内容添加到 div 中时,我想重新初始化 jScrollPane,这就是我到目前为止所得到的:
var pane = $('.content_pane')
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
$('.content_pane').jScrollPane();
pane.reinitialise();
}
它有点破坏页面,但我是 JavaScript 新手,所以我认为可能做错了什么。
更新:
function loadContent() {
$('#content').load(toLoad,'',showNewContent)
}
function showNewContent() {
$('#content').show(1,hideLoader());
$('.content_pane').jScrollPane();
pane.reinitialise();
}
它仍然只加载一次?!
更新 2:
function loadContent() {
$('#content').load(toLoad,'',showNewContent)
}
function showNewContent() {
$('#content').show(1,hideLoader());
$('.content_pane').jScrollPane();
var api = $('.content_pane').jScrollPane(
{
showArrows:true,
maintainPosition: false
}
).data('jsp');
api.getContentPane();
api.reinitialise();
}
HTML:
<div id="content_pane" class="content_pane">
<div id="content" >
<!-- content delivered here -->
</div>
</div>
非常简单。
I want to reinitialise jScrollPane when new content is added loaded to the div, heres what I got so far:
var pane = $('.content_pane')
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
$('.content_pane').jScrollPane();
pane.reinitialise();
}
It sort of breaks the page, but I'm new to JavaScript so I figure probably doing something wrong.
Updated :
function loadContent() {
$('#content').load(toLoad,'',showNewContent)
}
function showNewContent() {
$('#content').show(1,hideLoader());
$('.content_pane').jScrollPane();
pane.reinitialise();
}
It still only loads once?!
Update 2:
function loadContent() {
$('#content').load(toLoad,'',showNewContent)
}
function showNewContent() {
$('#content').show(1,hideLoader());
$('.content_pane').jScrollPane();
var api = $('.content_pane').jScrollPane(
{
showArrows:true,
maintainPosition: false
}
).data('jsp');
api.getContentPane();
api.reinitialise();
}
HTML :
<div id="content_pane" class="content_pane">
<div id="content" >
<!-- content delivered here -->
</div>
</div>
It's quite straight forward.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此代码:
在接收数据之前调用。考虑将此代码移至
showNewContent
。并从
showNewContent()
中删除()
。是回调。你应该给出函数,而不是调用它。对jScrollPane
的调用只能进行一次。这是更正后的版本:
This code:
Is called before you receive data. Consider moving this code to
showNewContent
.And remove
()
fromshowNewContent()
. It is callback. You should give function, not call it. Call tojScrollPane
should be made only once.Here is corrected version:
如果您使用的是 jScrollPane 2,则需要使用 getContentPane 方法来获取对窗格的引用以将内容加载到其中,如下例所示:
http://jscrollpane.kelvinluck.com/ajax.html
我不确定您的 HTML 结构(其中
#content
相对于.content-pane
),所以我无法给你一个完整的例子。然而,我在代码中注意到的另一个问题是pane
是对包含窗格的 jQuery 对象的引用。如果您想获取对 API (其中包含 reinitialise 方法)的引用,那么您初始化 jScrollPane 后需要访问.data('jsp')
属性。然而,无论如何,都不需要在jScrollPane
之后直接调用reinitialise
- 一旦窗格初始化,它们都具有相同的效果......If you are using jScrollPane 2 you need to use the getContentPane method to get a reference to the pane to load the content into as in this example:
http://jscrollpane.kelvinluck.com/ajax.html
I'm not sure of the structure of your HTML (where
#content
is relative to.content-pane
) so I can't give you a complete example. However another problem I notice in your code is thatpane
is a reference to the jQuery object containing your pane. If you want to get a reference to the API (which has the reinitialise method on it) then you'll need to access the.data('jsp')
property after initialising jScrollPane. However there is no need to callreinitialise
directly afterjScrollPane
anyway - they both have the same effect once a pane is initialised...