问题描述
- <canvas> 兼容IE8 , 文本(txt)无法在IE中显示出来
-
ctx.fillText(txt,x+3, y+15);加上这两个方法 文本(txt)还是无法在IE中显示出来,求助sos,谢谢
contextPrototype.measureText = function(textToDraw) {
var hiddenSpan = document.createElement('span');
hiddenSpan.style.font = this.font;
hiddenSpan.innerHTML = textToDraw;
var bodyNode = document.getElementsByTagName("body")[0];
bodyNode.appendChild(hiddenSpan);
var width = hiddenSpan.offsetWidth;
bodyNode.removeChild(hiddenSpan);
this.strokeStyle = '#000';
this.fillStyle = '#000';
this.font = '12px sans-serif';
return {"width" : width + 1};
}
contextPrototype.fillText=function(textToDraw, x, y) {
var vmlStr = [];
var textHeightStr = this.font.split("px")[0].replace(/(^s+)|(s+$)/g, "");
var textHeight = /^d+$/.test(textHeightStr) ? parseInt(textHeightStr) : 0;
vmlStr.push('
' >' + textToDraw,' ',
'');
this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));
};