Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use a Canvas in all modern browsers (incl. IE9). The following example won't work in IE7 and IE8, but I haven't tested there.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Line Test&lt;/title&gt; &lt;style type="text/css"&gt; #ruled { border: 1px solid red; } #textContainer { position: absolute; left: 0; top: 0; width: 580px; height: 1200px; font-size: 12px; margin: 10px; padding: 5px 10px; line-height: 20px; } &lt;/style&gt; &lt;script type="text/javascript"&gt; function drawLines(){ // get the canvas element using the DOM var canvas = document.getElementById('ruled'); var currentLineY = 0; // Make sure we don't execute when canvas isn't supported if (canvas.getContext){ // use getContext to use the canvas for drawing var ctx = canvas.getContext('2d'); ctx.strokeStyle = "#CCC"; ctx.beginPath(); // draw some lines (the +1.5 offsets the text baseline // and we use the .5 for crisp lines because the stroke() // method requires floats, not ints for (var i=1, imax=30; i&lt;imax; i++) { currentLineY = i*20 + 1.5; ctx.moveTo(0,currentLineY); ctx.lineTo(600,currentLineY); } ctx.stroke(); } else { alert('You need a modern browser to see the lines.'); } } &lt;/script&gt; &lt;/head&gt; &lt;body onload="drawLines()"&gt; &lt;canvas id="ruled" width="600" height="602"&gt;&lt;/canvas&gt; &lt;div id="textContainer"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. &lt;br&gt;&lt;br&gt; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload