滚动窗格高度问题

时间:2012-02-09 09:15:59

标签: javascript html css ajax

我使用了从此网站http://jscrollpane.kelvinluck.com/arrow_hover.html中提取的滚动条。我为一些文本集成了一个ajax show hide函数。我的问题是,如果我在滚动窗格中使用了ajax show hide,则滚动无法正常工作。如果我单击Click to open,则会在其下方打开一些文本。但是底部的一些文字不会显示出来。它被切断了。滚动高度不超过。

以下是我的HTML代码。

<div class="scroll-pane">
  <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in ligula id sem tristique ultrices
    eget id neque. Duis enim turpis, tempus at accumsan vitae, lobortis id sapien. Pellentesque nec orci
    mi, in pharetra ligula. Nulla facilisi. Nulla facilisi. Mauris convallis venenatis massa, quis
    consectetur felis ornare quis. Sed aliquet nunc ac ante molestie ultricies. Nam pulvinar ultricies
    bibendum. Vivamus diam leo, faucibus et vehicula eu, molestie sit amet dui. Proin nec orci et elit
    semper ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus
    mus. Sed quis urna mi, ac dignissim mauris. Quisque mollis ornare mauris, sed laoreet diam malesuada
    quis. Proin vel elementum ante. Donec hendrerit arcu ac odio tincidunt posuere. Vestibulum nec risus
    eu lacus semper viverra. </p>
  <p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
    Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit
    amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. </p>
  <p>
  <div class="avatar_content">
    <div><strong>KeysorSoze:</strong></div>
    <p>Spitfire might thwart the 3-peat but he won’t thwart The Dynasty.  One and done, Levi!</p>
    <div><a href="javascript:void(0);" onClick="javascript:ajaxshow('replybox');">Click to open</a></div>
  </div>
  <div id="replybox" style="display:none;">
    <div align="right" style="position:relative;"><a href="javascript:void(0);" onClick="javascript:ajaxhide('replybox');">close</a></div>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
      Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit
      amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
      Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
      Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit
      amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. </p>
  </div>
  <div style="clear:both"></div>
  </p>
  <p> last content</p>
</div>

这是我的css

.scroll-pane
{
    width: 500px;
    height: 200px;
    overflow:auto; background-color:#CCCCCC;
}

这是ajax show hide

的脚本
<script type="text/javascript">
function ajaxshow(id){
document.getElementById(id).style.display = 'block';
}
function ajaxhide(id){
document.getElementById(id).style.display = 'none';
}
function hide(id){
if (document.getElementById){
obj = document.getElementById(id);
obj.style.display = "none";
}
}

</script>

我该如何纠正?

2 个答案:

答案 0 :(得分:1)

当内容发生变化时,您需要重新初始化jScrollPane。这些方面的东西:

function ajaxshow(id){
  document.getElementById(id).style.display = 'block';
  jQuery('.scroll-pane').jScrollPane();
}
function ajaxhide(id){
  document.getElementById(id).style.display = 'none';
  jQuery('.scroll-pane').jScrollPane();
}

答案 1 :(得分:0)

也许您的问题是您正在使用的滚动窗格脚本在内容更改时不会自动更新。因此,您需要根据修改后的文本告诉脚本刷新

我不知道脚本,但我认为解决方案就在这里:

  

http://jscrollpane.kelvinluck.com/dynamic_content.html

如您所见,在将新文本放入容器内后,将调用.reinitialise()方法。

我可以继续:

// Create scroll pane
var pane = $('.scroll-pane')
pane.jScrollPane({ showArrows: true });
var api = pane.data('jsp');

// Append text (your "show more" link)
// [...]

// Refresh pane
api.reinitialise();