私が望む要素に等しい高さを設定する方法です。 高さを同じにするクラス名を要素に付けます。
<div class="sameElementHeight">
<img src="/path/to/Image" class="sameImageHeight">
<p>YOUR TEXT</p>
</div>
<div class="sameElementHeight">
<img src="/path/to/Image" class="sameImageHeight">
<p>YOUR TEXT</p>
</div>
<div class="sameElementHeight">
<img src="/path/to/Image" class="sameImageHeight">
<p>YOUR TEXT</p>
</div>
まず、このような関数を作成:bodyタグを閉じる前にそれを呼び出すその後
equalheight = function(container){
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
jQuery(container).each(function() {
$el = jQuery(this);
jQuery($el).height('auto')
topPostion = $el.position().top;
if (currentRowStart != topPostion) {
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
} else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
});
}
を:あなたに新しい要素を追加するとき
<script>
equalheight(".sameElementHeight");
equalheight(".sameImageHeight");
</script>
</body>
また、この機能を呼び出すことができます資料。 これは要素の高さを計算し、同じ高さに設定し、イメージでも同じことを行います。
私はそれが役に立ちそうです。
offsetHeightは何を返しますか? – adelowo
jalery – alireza
@alirezaを使用できる場合は、一般的な解決策を提供できます。お試しください。 jQueryが何かできるのであれば、これは純粋なJSでも利用可能です。 –