Skip to content
Daniel Gimenez edited this page Jul 26, 2013 · 4 revisions

dgBlocks is a simple plugin for positioning blocks relative to others, and for filling up the remaining height within a parent container.

It is located at \Scripts\Plugins\dgBlocks-1.0.3.js

Members

Properties

  • pollingInterval: Determines how often objects using fillHeight will check if their parent container has been resized.

Methods

  • fillHeight: Selected elements with fill any remaining height of the parent. If the window or parent is resized, the selected elements will shrink/grow with the new available space.
  • moveRightOf: Accepts as an argument an html element, and an optional x-offset. Will position selected elements to the right of the passed elements, with any additional offset. Only works with blocks that have position:absolute style.
  • moveUnder: Accepts as an argument an html element, and an optional y-offset. Will position selected elements directly under the passed elements, plus with any additional offset. Only works with blocks that have position:absolute style.

Usage

<div style="height:400px">
  <div style="background:red; height:100px"></div>
  <div style="background:blue; height:100px"></div>
  <div id="divFill" style="background:green; height:100px"></div>
</div>

<div style="height:400px; position:relative">
  <div id="div1" style="position:absolute; height:50px; width:50px"></div>
  <div id="div2" style="position:absolute; height:50px; width:50px; top:50px; left:50px"></div>
</div>
<script>
  // decrease polling interval
  $.fn.blockUtil.pollingInterval = 500;

  // move to the right of #div2 with 50px width between them.
  $('#div1').blockUtil('moveRightOf', '#div2', 50);

  // move under #div2
  $('#div1').blockUtil('moveUnder', '#div2');

  // automatically fill height
  $('#divFill').blockUtil('fillHeight');
</script>

Clone this wiki locally