functionbresenham(x0, y0, x1, y1) { var px = []; var y = y0; var m = Math.round((Math.abs(y1 - y0) / (x1 - x0)) * 100) / 100; var dely = 0; for (var j = 0, i = x0; i <= x1; i++, j++) { px[j] = [i, y]; dely += m; if (dely >= 0.5) { y = y + 1; dely -= 1; } } return px; }
functionfn() { var ret = []; var numWidth = $("#oblique").width(); var numLeft = $("#oblique").offset().left; var numTop = $("#oblique").offset().top; var arr = bresenham(numLeft, numTop, numLeft + numWidth, numTop + 80); var x, y; for (var i = 0; i < arr.length; i++) { x = arr[i][0]; y = arr[i][1]; ret.push( ' <div style="width:1px;height:1px;font-size:0;background-color:black;position:absolute;left:' + x + "px;top:" + y + 'px"> </div>' ); } $("#obliquebox").html(ret.join("")); }
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<tablewidth="100%"style="BORDER-COLLAPSE: collapse"> <tr> <tdwidth="20%"id="oblique"style="border-bottom: none;"> <divid="obliquebox"></div> <div> <divalign="right"> A </div> <divalign="left"> B </div> </div> </td> </tr> </table>