The point is, there is a block with

position: fixed

and there is another under it

div

here's how to do it so that when a block with

position: fixed

visible, the bottom went down to the height of this block?

Here is what I tried to do.

$(".helpMenuWhite").click(function(){ if($(".helpMenuWhite").css("position") == "fixed") { $(".test").css("margin-top","100px"); }else{ $(".test").css("display","none"); } }); 
  • And what affects the visibility of the block with fix. positioning? Is it shown-hiding script? - Sergiks
  • @gold it will remain under it if the block is “c” with the css property position: fixed and margin-top: 0; If the c block has position! = Fixed, then the second block will be hidden. - lampa
  • Maybe we are talking about a dynamic layout: when the page is scrolling, and under the fix. the block turns out to be different, it would move lower to fix. the top did not overlap it? - Sergiks
  • @gold if you have jQuery, then this: .css ("margin-top", value + 100); If not, you first need to bring the result to a numerical form, since the height usually looks like this: "100px", with the help of the function, these "px" are trimmed, ie: parseInt (window.getComputedStyle (block_c, null) .height) + 100 + px; - lampa

1 answer 1

 var block_c = ... var block_d = ... if(block_c.style.display != 'none') { block_d.style.top = parseInt(window.getComputedStyle(block_c, null).top) + parseInt(window.getComputedStyle(block_c, null).height) + 'px'; } 

Block d also needs to be added: position (relative, absolute, fixed)

  • @gold jsfiddle.net/8syNN - lampa
  • @gold block_d.style.marginTop = window.getComputedStyle (block_c, null) .height; - lampa
  • @lampa is not even that, or I explain it crookedly - Goldy
  • @gold draw what is and what you want to receive. - lampa
  • @lampa See 1) If the block <div class="position:fixed;height:30px;"> fixed, a margin-top:30px added to the downstream block, 2) If not, this block gets display:none - Goldy