webshim polyfill 画布在 IE7 模式下无法工作

发布于 2024-11-08 21:00:55 字数 1462 浏览 5 评论 0原文

我在让 webshims 插件 canvas polyfill 工作时遇到问题。

使用 IE7 模式在 IE9 中出现以下错误:

  SCRIPT438: Object doesn't support property or method 'fillRect'
  problem.html, line 21 character 7

当我尝试运行此代码时:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
    <title>DealingTree</title>
    <meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" src="/js/modernizr.js"> </script>
    <script type="text/javascript" src="/js/jquery.js"> </script>
    <script type="text/javascript" src="/js/sssl.js"> </script>
    <script type="text/javascript" src="/js/webshims/js-webshim/minified/polyfiller.js"> </script>
  </head>
  <body>
    <canvas id="savings" height="350" width="700"> </canvas>
    <script type="text/javascript">
      //<![CDATA[
      window.FlashCanvasOptions = { disableContextMenu: true };
      $.webshims.setOptions( 'canvas', { type: 'flashpro' } );
      $.webshims.polyfill('canvas');
      var canvas = $('#savings');
      var context = canvas.getContext('2d');
      context.fillStyle='#F00';
      context.fillRect(0,0,700,350);
      //]>
    </script>
  </body>
</html>

无论我使用默认值 (excanvas) 还是 flashpro,都会出现问题。

更新:在我看来, getContext() 返回的是 jQuery 对象而不是上下文。

请帮忙?

I am having problems getting the webshims plugin canvas polyfill to work.

I get the following error in IE9 using IE7 mode:

  SCRIPT438: Object doesn't support property or method 'fillRect'
  problem.html, line 21 character 7

when I try to run this code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
    <title>DealingTree</title>
    <meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" src="/js/modernizr.js"> </script>
    <script type="text/javascript" src="/js/jquery.js"> </script>
    <script type="text/javascript" src="/js/sssl.js"> </script>
    <script type="text/javascript" src="/js/webshims/js-webshim/minified/polyfiller.js"> </script>
  </head>
  <body>
    <canvas id="savings" height="350" width="700"> </canvas>
    <script type="text/javascript">
      //<![CDATA[
      window.FlashCanvasOptions = { disableContextMenu: true };
      $.webshims.setOptions( 'canvas', { type: 'flashpro' } );
      $.webshims.polyfill('canvas');
      var canvas = $('#savings');
      var context = canvas.getContext('2d');
      context.fillStyle='#F00';
      context.fillRect(0,0,700,350);
      //]>
    </script>
  </body>
</html>

The problem happens whether I use the default (excanvas) or flashpro.

UPDATE: It appears to me that getContext() is returning a jQuery object instead of a context.

Help, please?

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

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

发布评论

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

评论(1

開玄 2024-11-15 21:00:55

我通过电子邮件收到了插件作者 Alexander Farkas 的以下解释:

问题如下。网络垫片
使用脚本进行异步填充
装载机。这对性能有好处
在现代浏览器中。这也意味着,
你必须等到
画布功能已准备就绪。

你的代码应该包裹在
domready 事件,一切都很好:

window.FlashCanvasOptions = { disableContextMenu: true };
$.webshims.setOptions( 'canvas', { type: 'flashpro' } );
$.webshims.polyfill('canvas');
$(function(){
     var canvas = $('#savings');
     var context = canvas.getContext('2d');
     context.fillStyle='#F00';
     context.fillRect(0,0,700,350);
});

您可以找到有关您的更多信息
文档中的问题@
http://afarkas.github.com/webshim/demos/index.html #polyfill-ready

I received the following explanation from the plugin author, Alexander Farkas, via email:

The problem is the following. Webshims
does async polyfilling using a script
loader. Which is good for performance
in modern browsers. This also means,
that you have to wait untill the
canvas feature is ready.

Your code should be wrapped in a
domready event and everything is fine:

window.FlashCanvasOptions = { disableContextMenu: true };
$.webshims.setOptions( 'canvas', { type: 'flashpro' } );
$.webshims.polyfill('canvas');
$(function(){
     var canvas = $('#savings');
     var context = canvas.getContext('2d');
     context.fillStyle='#F00';
     context.fillRect(0,0,700,350);
});

You find more informations about your
problem in the documentation @
http://afarkas.github.com/webshim/demos/index.html#polyfill-ready

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