I am trying to figure out how to flow text automatically, using CSS and jQuery.
Here is how to make text flow into two stacks (which I found on this page):
<script type="text/javascript">
$(document).ready(function() {
var size = $("#data > p").size();
$(".Column1 > p").each(function(index){
if (index >= size/2){
$(this).appendTo("#Column2");
}
});
});
</script>
<div id="data" class="Column1" style="float:left;width:300px;">
<!-- data Start -->
<p>This is paragraph 1. Lorem ipsum ... </p>
<p>This is paragraph 2. Lorem ipsum ... </p>
<p>This is paragraph 3. Lorem ipsum ... </p>
<p>This is paragraph 4. Lorem ipsum ... </p>
<p>This is paragraph 5. Lorem ipsum ... </p>
<p>This is paragraph 6. Lorem ipsum ... </p>
<!-- data Emd-->
</div>
<div id="Column2" style="float:left;width:300px;"></div>
Is there a way to convert the JS above so that if flows into three columns instead of just two?
I was thinking maybe
<script type="text/javascript">
$(document).ready(function() {
var size = $("#data > p").size();
$(".Column1 > p").each(function(index){
if (index >= size/3){
$(this).appendTo("#Column2");
}
});
$(".Column2 > p").each(function(index){
if (index >= size*2/3){
$(this).appendTo("#Column3");
}
});
});
</script>
<div id="data" class="Column1" style="float:left;width:250px;">
<!-- data Start -->
<p>This is paragraph 1. Lorem ipsum ... </p>
<p>This is paragraph 2. Lorem ipsum ... </p>
<p>This is paragraph 3. Lorem ipsum ... </p>
<p>This is paragraph 4. Lorem ipsum ... </p>
<p>This is paragraph 5. Lorem ipsum ... </p>
<p>This is paragraph 6. Lorem ipsum ... </p>
<!-- data Emd-->
</div>
<div id="Column2" style="float:left;width:250px;"></div>
<div id="Column3" style="float:left;width:250px;"></div>
But that doesn't work - it still just splits it into two columns.
I'm pretty sure I'm missing something very simple and small, but I'm confounded.
I'd like to make the above work, rather than use the Columnizer jQuery Plugin, which is far too much for my meager needs.
Thank you! -Tim