我想让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;
}如果我输入"height:100%;“或"height:auto;",内容就会消失!为什么它接受px而不是%?我想要理解它...
我应该修改/添加JS/JQuery代码的哪一部分才能插入该部分的流体高度?
发布于 2012-11-12 12:50:35
没有更多的示例代码是很难理解的(请养成发布更多代码的习惯),但我认为这就是你想要的。
-为什么不跟踪上下文的高度(外部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.https://stackoverflow.com/questions/13332749
复制相似问题