调用子 Div 时,JscrollPane Div 不起作用
在“主”div 上使用 JscrollPane,并将内容放在该 div 内的子 div 中。我使用 jquery show/hide 来加载 onClick 内容,但子 div 不会出现。如果我删除 JscrollPane 它工作正常:(
HTML:
<h3 onclick="internalNav('testTwo')">Click to see Div Two</h3>
<div id="content" class="scroll-pane">
<div id="testOne">
<h1>Title 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div id="testTwo">
<h1>Title 1/h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
JS
$(document).ready(function(){
//Hide all divs, then show first div
$("#content > div").hide()
$("#content > div:first").show()
$(function(){
$('.scroll-pane').jScrollPane();
});
});
function internalNav(divId) {
$("#content > div").not('#' + divId).hide()
$('#' + divId).fadeIn()
}
我看不出这里出了什么问题!
Using JscrollPane on a "master" div, and have the content in children divs within that div. I'm using jquery show/hide to load the content onClick, but the child div won't appear. If I remove JscrollPane it works fine :(
HTML:
<h3 onclick="internalNav('testTwo')">Click to see Div Two</h3>
<div id="content" class="scroll-pane">
<div id="testOne">
<h1>Title 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div id="testTwo">
<h1>Title 1/h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
JS
$(document).ready(function(){
//Hide all divs, then show first div
$("#content > div").hide()
$("#content > div:first").show()
$(function(){
$('.scroll-pane').jScrollPane();
});
});
function internalNav(divId) {
$("#content > div").not('#' + divId).hide()
$('#' + divId).fadeIn()
}
I can't see what's wrong here!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改 jScrollPane 内部的内容(或更改该内容的可见性)后,您需要重新初始化 jScrollPane。这是一个示例:
http://jscrollpane.kelvinluck.com/invisibles.html
另外,我请注意,您在
document.ready
块内有一个$(function()
块。您不需要该附加块 - 您可以直接应用 jScrollPane,因为您已经在document.ready
块中作为旁注,在 h3 中使用 onclick 属性不被认为是最佳实践,相反,您可以使用 jQuery 添加事件侦听器。重新初始化并使用更清晰的事件绑定:
将 HTML 中的 h3 替换为:
You need to reinitialise jScrollPane after changing the content inside it (or changing the visibility of that content). Here is an example:
http://jscrollpane.kelvinluck.com/invisibles.html
Also, I notice that you have a
$(function()
block inside adocument.ready
block. You don't need that additional block - you can just apply jScrollPane directly since you are already inside adocument.ready
blockAs a side note, using the onclick attribute in your h3 isn't considered best practice. Instead you could add an event listener with jQuery. This is an example showing both the reinitialisation and using the cleaner event binding:
With the h3 from your HTML replaced with: