Don*_*hey 12 javascript safari canvas
我一直在尝试使用<canvas>标签绘制简单的图表和图表,到目前为止,它很容易使用.我想到了一个问题.我无法弄清楚如何<canvas>在Safari中绘制文本.在Firefox 3.0中,我可以这样做:
Chart.prototype.drawTextCentered = function(context, text, x, y, font, color) {
if (context.mozDrawText) {
context.save();
context.fillStyle = color;
context.mozTextStyle = font;
x -= 0.5 * context.mozMeasureText(text);
context.translate(x, y);
context.mozDrawText(text);
context.restore();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经看到fillText()了Apple的Safari文档中的方法,但它似乎在Safari 3.2中不受支持.这只是目前缺失的东西,还是一些保密的秘密?
Bri*_*ell 14
我不相信Safari 3.2支持在画布中渲染文本.
根据这篇博客,Safari 4 beta支持基于HTML 5 canvas文本API将文本重新发送到画布.
编辑:我已确认以下代码段在Safari 4 beta中有效:
<canvas id="canvas"></canvas>
<script>
var context = document.getElementById("canvas").getContext("2d");
context.fillText("Hello, world!", 10, 10);
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18961 次 |
| 最近记录: |