簡體   English   中英

獲取具有oveflow的div的內容高度:隱藏樣式

[英]get contents height of div that has oveflow:hidden style

我正在為jquery設計一個垂直滾動條插件。 我的插件接受一個height值作為選項,如果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);

我可以在應用'overflow:hidden'之前獲得div的高度,但是問題是我希望它即使從一開始就具有溢價:隱藏的樣式也可以。

您應該在頁面上具有一個隱藏的div ,該divwidth應相同,但應overflow auto 一旦您的插件被調用/實例化,請使用該隱藏的div的高度並執行您想要的操作。

我知道應該工作的一種方法是在溢出內部包含一個content元素,並獲取它的高度,因為它應該保留其height值。

.css()方法應該可以工作

$(this).css('height'); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM