2017-08-16 198 views
0

我正在嘗試獲取originalElement的clientHeight,它是傳入調整大小事件(see documentation on the resize event)的ui參數的屬性。獲取clientHeight jQuery可調整大小

我的代碼如下:

mapTableContainer.resizable({ 
    handles: 'n', 
    resize: function(event, ui){ 
     console.log(ui.originalElement.clientHeight); 
    } 
}); 

的問題是我不斷收到「未定義」爲clientHeight。我可以看到clientHeight,如果我只是登錄ui.originalElement,所以我確信我只是訪問它錯誤,只是不確定訪問它的正確方法。

(控制檯洛ui.originalElement的圖片;看到clientHeight)

enter image description here

回答

1

您可以使用:

  • this.clientHeight

  • ui.element[0].clientHeight

元件:被調整大小的表示元jQuery對象

originalElement:

:表示原始元件它被包裹

的片段之前的jQuery對象

$("#resizable").resizable({ 
 
    handles: 'n', 
 
    resize: function(event, ui){ 
 
     console.log('Original Height: ' + ui.originalSize.height + 
 
     ' Current height: ' + ui.size.height + 
 
      ' this clientheight: ' + this.clientHeight); 
 
    } 
 
});
#resizable { width: 150px; height: 150px; padding: 0.5em; } 
 
#resizable h3 { text-align: center; margin: 0; }
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/> 
 
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> 
 
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> 
 

 

 
<div id="resizable" class="ui-widget-content"> 
 
    <h3 class="ui-widget-header">Resizable</h3> 
 
</div>