Javascript jquery jScrollPane:滚动内容高度超过项目列表大小

Javascript jquery jScrollPane:滚动内容高度超过项目列表大小,javascript,jquery,jscrollpane,Javascript,Jquery,Jscrollpane,我正在为我的项目使用jScrollPane插件。在我的项目中有一个可以滚动的项目列表。稍后将从xml加载项。最初有两个项目。问题是,一开始滚动面板的高度超过了主内容的大小&滚动条会一直向下移动,即使滚动条中的项目不超过2个。我的代码如下: <script> $('#scrollerContent').jScrollPane(); </script> <body> <div id="container" style="max-height:229; vi

我正在为我的项目使用jScrollPane插件。在我的项目中有一个可以滚动的项目列表。稍后将从xml加载项。最初有两个项目。问题是,一开始滚动面板的高度超过了主内容的大小&滚动条会一直向下移动,即使滚动条中的项目不超过2个。我的代码如下:

<script>
$('#scrollerContent').jScrollPane();
</script>

<body>
<div id="container" style="max-height:229; visibility:hidden">
<div id="scrollerContent" style="max-height:229">
<div id="1stContent">1stContent</div>
<div id="2ndContent">2ndContent</div>
<div id="3rdContent">3rdContent</div>
<div id="4thContent">4thContent</div>
</div>
</div>
</body>

$('#scrollerContent').jScrollPane();
1内容
第二内容
第三方内容
4th内容
项目列表是从鼠标单击事件加载的:

<div id="listBar" onClick="loadItems()"></div>

loadItems(){

var divHeight=145;

if(itemLoaded){

if(3rdItemLoaded){

document.getElementByID("3rdContent").style.visibility= visible;
document.getElementByID("container").style.height= divHeight+ "px";
document.getElementByID("scrollerContent").style.height= divHeight+ "px";

}

if(4thItemLoaded){

document.getElementByID("4thContent").style.visibility= visible;
document.getElementByID("container").style.height= divHeight+ "px";
document.getElementByID("scrollerContent").style.height= divHeight+ "px";

}

}

else{ //By default 2 items loaded 

var divHeight= 145;
document.getElementByID("1stContent").style.visibility= visible;
document.getElementByID("2ndContent").style.visibility= visible;
document.getElementByID("container").style.height= divHeight+ "px";
document.getElementByID("scrollerContent").style.height= divHeight+ "px";

}

}

loadItems(){
var-divHeight=145;
如果(已加载项){
如果(3rdItemLoaded){
document.getElementByID(“第三方内容”).style.visibility=visible;
document.getElementByID(“容器”).style.height=divHeight+“px”;
document.getElementByID(“scrollerContent”).style.height=divHeight+“px”;
}
如果(4次加载){
document.getElementByID(“4thContent”).style.visibility=visible;
document.getElementByID(“容器”).style.height=divHeight+“px”;
document.getElementByID(“scrollerContent”).style.height=divHeight+“px”;
}
}
else{//默认情况下加载2项
var-divHeight=145;
document.getElementByID(“1stContent”).style.visibility=visible;
document.getElementByID(“2ndContent”).style.visibility=visible;
document.getElementByID(“容器”).style.height=divHeight+“px”;
document.getElementByID(“scrollerContent”).style.height=divHeight+“px”;
}
}
如果程序达到默认情况下加载2项的最后一个else条件,则会导致问题。滚动内容高度超过。我做错什么了吗