我正在为 jquery 设计一个垂直滚动条插件。我的插件接受高度值作为选项,如果 div 高度超过给定高度,滚动条将可见。现在的问题是我需要获取 div 内容的真实高度。
<div id="scroll">
Contents Here
</div>
jQuery:
$.fn.vscrollbar = function (options) {
.
.
.
var contentHeight=this.contents().height() //that is not working correctly
if(contentHeight > options.height){
this.css({overflow : 'hidden'}).height(options.height);
}
.
.
.
})(jQuery);
我可以在应用“溢出:隐藏”之前获得 div 的高度,但问题是我希望它能够工作,即使它从一开始就有溢出:隐藏样式。