DTP flow text multicol

by Ben Clayton

HTML

<div class="cola start">
  It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here,
  content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions
  have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</div>
<div class="colb end">
</div>
<hr/>

CSS

.cola,
.colb {
  border: 1px solid red;
  display: inline-block;
  vertical-align: top;
  padding: 0px;
}

.cola {
  width: 69%;
}

.colb {
  width: 29%;
}

JavaScript

function distribute() {
  debugger;
  var txt = $(".start").html();
  txt += $(".end").html();

  var m = 0;
  var x = 1000;
  var m2 = m;
  do {
    m2 = m;
    m = split(txt, m);
    var diff = ($(".start").height() < $(".end").height());
  } while (x-- && diff);
  split(txt, m2);
}

function split(txt, m) {
  var l = txt.length;
  m = txt.indexOf(" ", m + 1)
  var a = txt.substr(0, m);
  var b = txt.substr(m, l - m);
  $(".start").html(a);
  $(".end").html(b);
  return m;
}


distribute();