[英]get contents height of div that has oveflow:hidden style
I'm designing a vertical scroll-bar plugin for jquery. 我正在为jquery设计一个垂直滚动条插件。 my plugin accepts a height value as option and if the div height exceeds the given height the scroll-bar will be visible. 我的插件接受一个height值作为选项,如果div高度超过给定的高度,则滚动条将可见。 now the problem is I need to get the real height of the div content. 现在的问题是我需要获取div内容的真实高度。
<div id="scroll">
Contents Here
</div>
jquery: 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);
I can get the height of div before applying 'overflow:hidden' but the problem is I want this to work even if it has overflow:hidden style from the begining. 我可以在应用'overflow:hidden'之前获得div的高度,但是问题是我希望它即使从一开始就具有溢价:隐藏的样式也可以。
You should have a hidden div
on the page, of the same width
but overflow auto
. 您应该在页面上具有一个隐藏的div
,该div
的width
应相同,但应overflow auto
。 As soon as your plugin is called/instantiated, take the height of that hidden div
and do what you want. 一旦您的插件被调用/实例化,请使用该隐藏的div
的高度并执行您想要的操作。
我知道应该工作的一种方法是在溢出内部包含一个content元素,并获取它的高度,因为它应该保留其height值。
.css()方法应该可以工作
$(this).css('height');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.