我想个性化一个具有流畅高度的div的滚动条:
section {
max-height:70%;
overflow-y:auto;
}
我找到了两个智能光片:一个Jquery插件(http://baijs.nl/tinyscrollbar/)和一个纯JS一个(http://gondo.webdesigners.sk/javascript-scrollbar/)。问题是这些片段不接受高度的%值。例如,使用tinyscrollbar,我必须把它:
section .viewport {
width: auto;
height:440px;
overflow: hidden;
position: relative;
}
如果我把“身高:100%;”或“身高:自动;”,内容消失!为什么它接受px而不是%?我想理解它......
为了插入部分的流体高度,我应该更改/添加JS / JQuery代码的哪一部分?
答案 0 :(得分:1)
如果没有更多的示例代码(习惯于发布更多代码),很难遵循,但我认为这样的事情就是你所追求的。
---为什么不跟踪上下文的高度(外部div?)和内部div(部分)的高度,并在它们发生变化时计算它们?
var context_height = $("#context_div").height();
var section_height = $("section#id").height();
var percentage = section_height / context_height;
var measurement = percentage + "%";
$(section_height).css("height", measurement); // trigger this with a callback if heights need updating - possibly even re-initializing any scroll plugins, if necessary.