L
L
lynnikvadim2015-11-03 00:03:05
PHP
lynnikvadim, 2015-11-03 00:03:05

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

2 answer(s)
A
amatory10, 2015-11-03
@lynnikvadim

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';
}

V
Vitaly Inchin ☢, 2015-11-03
@In4in

var $block = $("#block"), height = $block.height();

$block.children().each(function(i){
   $(this)[i + 1 > Math.floor(height / 150) ? "hide" : "show"]();
});

or
$block.children().show()
    .filter(":nth-child(" + Math.floor(height / 150) + ") ~ *")
.hide();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question