2016-12-28 5 views
-2

質問が修正されました。 オブジェクトオブジェクトは私の間違いでした。JQueryを使用してDIVの高さを取得する

私はいくつかのdivの高さを検出し、その値を別のdivに割り当てようとしています。

しかし、私が書いたコードは私に正しい答えを得ていない(私はJavascript/Jqueryでそれほど良くない)。

CSS & HTMLはデモ用です。

残高を.iframeクラスに残していますが、Jquery/Javascriptを使用しています。

私の構造はほとんど同じで、containerwidthは流動的です。

$(document).ready(function() { 
 
    var lhs = $('.section-updates').parent().outerHeight(); 
 
    console.log(lhs); 
 
    var rhs = $('.customer-focus').parent().height(lhs); 
 
    console.log(rhs); 
 
    var cfH = $('.customer-focus').outerHeight(); 
 
    $('.iframe').height(rhs - cfH); 
 
});
.section-updates { 
 
    height: 500px; 
 
    width: 50%; 
 
    background: purple; 
 
    float: left; 
 
} 
 
.customer-focus { 
 
    height: 200px; 
 
    background: yellow; 
 
    float: left; 
 
    width: 50%; 
 
} 
 
.iframe { 
 
    min-height: 100px; 
 
    background: tomato; 
 
    float: left; 
 
    width: 50%; 
 
} 
 
.container { 
 
    width: 95%; 
 
    height: 100%; 
 
    margin: 0 auto; 
 
    overflow: hidden; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="container"> 
 

 
    <div class="section-updates"></div> 
 
    <div class="customer-focus"></div> 
 
    <div class="iframe"></div> 
 

 
</div>

+2

jQueryの '高さ(値)'関数はjQueryオブジェクトを返す、参照印刷し、なぜ、それはです[ documentation(http://api.jquery.com/height/#height2) –

+0

.height()は読み込み専用だと思うので、 'var rhs'を始めるあなたの行は敬遠します。 –

+1

'console.log( 'LHS --------:'、lhs);' – Satpal

答えて

1

あなたは高さのパラメータを渡しているので、あなたが高さを設定しているvar rhs = $('.customer-focus').parent().height(parseInt(lhs)); ...それは、オブジェクトのコンテンツラインで

console.log(lhs); 
0

が表示されます。このように、コンソールにしてください関数parseInt(lhs)を設定した後は明らかにオブジェクトを返します。 console.log("RHS -----",rhs)のように使用するか、またはconsole.log(JSON.stringify(lhs))を使用するか、またはあなただけの高さが必要な場合console.logrhs=$('.customer-focus').parent().height();

0

,+を置き換える使用しています。あなたが+を使用する場合には、1つの文字列にすべての値をCONCATしようとlhsが、それは単に文字列に変換することができないオブジェクトがあるので、それは[object Object]

関連する問題