HTML5 Canvas、excanvas.js 和IE。 IE7 中不显示文本

发布于 2024-11-08 02:49:57 字数 1658 浏览 0 评论 0原文

这个简单的 Canvas 脚本创建一个带有边框和文本的矩形。它适用于 Chrome 和 FireFox。但该文本在 Internet Explorer 7.0 中不起作用。我已经包含了 excanvas.js;因此,矩形和边框会显示在 IE 7 中。但是,文本不会显示在 IE 7 中。我想知道是否可以让这个简单的脚本在 IE 7 和 8 中工作?

<!DOCTYPE html> 
<html lang="en">
<head>
    <link href = "style.css" type = "text/css" rel = "stylesheet" />
    <script src="js/excanvas.js" type="text/javascript"></script>

    <script type="text/javascript"> 
    function addBox(){
        var c = document.getElementById("myCanvas");
        context=c.getContext("2d"); 

        //Inner rectangle with shadow
        context.fillStyle = 'red';
        context.shadowColor="brown";
        context.shadowBlur = 20;
        context.fillRect(402,227,96.5,48.5); 
        context.shadowColor = null; 
        context.shadowBlur = null;      

        //Outer Rectangle
        context.lineWidth = '5';
        context.strokeStyle='green';    
        context.strokeRect(400,225,100,50); //draws just the edges of a rectangle               

        //font
        context.font = '17px Arial';        
        context.textBaseline = 'top';  
        context.fillStyle    = 'black';
        context.fillText  ('hello', 433, 243);
    }

    </script>
</head>

<body onload="addBox()"> 

    <canvas id="myCanvas" width="900" height="500">Your browser does not support the canvas element.</canvas> <br />
    <script type="text/javascript">     
        c = document.getElementById("myCanvas"); 
        cxt4=c.getContext("2d");
        resetCanvas();
    </script>
</body>
</html>

This simple Canvas script creates a rectangle with a border and text. It works in Chrome and FireFox. But the text does not work in Internet Explorer 7.0. I have included excanvas.js; for this reason the rectangle and border show up in IE 7. However, the text is not showing up in IE 7. I want to know if it is possible to get this simple script to work in IE 7 and 8?

<!DOCTYPE html> 
<html lang="en">
<head>
    <link href = "style.css" type = "text/css" rel = "stylesheet" />
    <script src="js/excanvas.js" type="text/javascript"></script>

    <script type="text/javascript"> 
    function addBox(){
        var c = document.getElementById("myCanvas");
        context=c.getContext("2d"); 

        //Inner rectangle with shadow
        context.fillStyle = 'red';
        context.shadowColor="brown";
        context.shadowBlur = 20;
        context.fillRect(402,227,96.5,48.5); 
        context.shadowColor = null; 
        context.shadowBlur = null;      

        //Outer Rectangle
        context.lineWidth = '5';
        context.strokeStyle='green';    
        context.strokeRect(400,225,100,50); //draws just the edges of a rectangle               

        //font
        context.font = '17px Arial';        
        context.textBaseline = 'top';  
        context.fillStyle    = 'black';
        context.fillText  ('hello', 433, 243);
    }

    </script>
</head>

<body onload="addBox()"> 

    <canvas id="myCanvas" width="900" height="500">Your browser does not support the canvas element.</canvas> <br />
    <script type="text/javascript">     
        c = document.getElementById("myCanvas"); 
        cxt4=c.getContext("2d");
        resetCanvas();
    </script>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2024-11-15 02:49:57

我刚刚在我身上尝试过这个并得到了相同的结果。然后我发现我使用的是早期版本的excanvas。使用此版本 并且它在 IE8 中工作。尚未在 IE7 上进行测试,但幸运的话它会起作用。

史蒂夫

I just tried this on mine and had the same results. Then I found that I was using an earlier revision of excanvas. Ran the code again with this version and it worked in IE8. Haven't tested on IE7 but with some luck it will work.

Steve

陌路黄昏 2024-11-15 02:49:57

当我更改 excanvas.js 文件时, fillText 正在工作
http://canvas-text.googlecode.com/svn-history /r48/trunk/excanvas.js

The fillText is working when i changed excanvas.js file
http://canvas-text.googlecode.com/svn-history/r48/trunk/excanvas.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文