Answer the question
In order to leave comments, you need to log in
How to show a certain number of blocks based on the height of the parent?
How to show a certain number of blocks based on the height of the parent?
There is a block, its height is not constant. In this block, there are more blocks with a height of 150px.
How can I make it so that if the height of the parent is, for example, 500px, then only show three nested blocks.
Answer the question
In order to leave comments, you need to log in
for example like this:
var outerDiv = document.getElementsByClassName('div1')[0];
if(outerDiv.offsetHeight === 500) {
var divChild = outerDiv.children;
for(var i = 0, max = divChild.length; i < max; i++)
divChild[i].style.display = 'block';
}
var $block = $("#block"), height = $block.height();
$block.children().each(function(i){
$(this)[i + 1 > Math.floor(height / 150) ? "hide" : "show"]();
});
$block.children().show()
.filter(":nth-child(" + Math.floor(height / 150) + ") ~ *")
.hide();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question