我需要一个脚本在画布红色框中与右侧的 html-table-tds 并排绘制...
它是如何完成的:http: //jsfiddle.net/KaDnQ/1/
html:
<table border="1">
<tr>
<td valign="top">
<table class="t2" border="1">
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
</table>
</td>
<td valign="top"><canvas id="x"></canvas></td>
</tr>
</table>
CSS:
body {
margin: 30px;
}
.t2 {
border-collapse: collapse;
border-spacing: 0;
}
.t2 td {
padding: 5px;
text-align: center;
}
canvas {
border: 1px dashed green;
}
JS:
var canvasWidth = $(".t2").outerWidth()*3;
var canvasHeight = $(".t2").outerHeight();
var c = document.getElementById("x");
var c2 = c.getContext("2d");
c.width = canvasWidth;
c.height = canvasHeight;
$('.t2 td:odd').each(function() {
var cur = $(this);
var topOffset = 0;
var shouldCount = true;
var h = $(this).outerHeight();
$('.t2 td').each(function() {
if (shouldCount) {
topOffset += h;
if (cur.is(this)) {
topOffset -= h;
shouldCount = false;
}
}
});
c2.fillStyle = '#f00';
c2.beginPath();
c2.moveTo(0, topOffset);
c2.lineTo(25, topOffset);
c2.lineTo(25, topOffset+h);
c2.lineTo(0, topOffset+h);
c2.closePath();
c2.fill();
});
这是它在 Chrome 中的样子(正确):
问题是Firefox中的下部框从它们的“父母” tds 中抵消了。
Firefox 渲染错误的原因是什么以及如何解决?
更新: FF 19 (mac)和IE 9 (win)出现错误渲染!