I'm designing a vertical scroll-bar plugin for jquery. my plugin accepts a height value as option and if the div height exceeds the given height the scroll-bar will be visible. now the problem is I need to get the real height of the div content.
<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);
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.
You should have a hidden div
on the page, of the same width
but overflow auto
. As soon as your plugin is called/instantiated, take the height of that hidden div
and do what you want.
我知道应该工作的一种方法是在溢出内部包含一个content元素,并获取它的高度,因为它应该保留其height值。
.css()方法应该可以工作
$(this).css('height');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.