In a former post I already presented the new CSS 3 column module and some funky stuff one can do with it.
However sometimes you want to provide your end users the possibility to decide for themselves how many columns they want to see. The following sample will do just that with the help of some javascript and the new HTML 5 range input type.
The following CSS is used to style up some range of text from the beginning:
#test { column-count: 3; column-rule:2px solid #000; column-gap:80px; }
to style up a div element with id test:
<h3>How many columns?</h3> <input type="range" min="1" max="5" onchange="changeColumnCount(this)"> <div id="test"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla dignissim mattis justo, sit amet volutpat turpis convallis vel. Etiam pulvinar tincidunt diam, sit amet ornare justo </p> </div>
Note the type of the input element: range. I specified the min and max values so there can be only one column or a maximum of five columns. The onchange event will call the following javascript function which takes care of the behavior part and makes the magic happen:
<script type="text/javascript"> function changeColumnCount(meter) { document.getElementById('test').style.columnCount = meter.value; } </script>
The meter value gets set to the column-count CSS property. Notice the way it is done in javascript, not via column-count but via the element’s property style.columnCount. Make sure that you have the casing right as javascript is a case sensitive language!
I used Internet Explorer 10 on Windows 8 and Opera on Windows 7 to test the feature:
The second IE10 is the Metro version. Note the number 4 coming over the meter. This shows up when dragging the slider from one value to another and disappears again when you release the slider.
The full code to test this out:
Have fun with this!
Grz, Kris.
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Kris van der Mast
E-mail