2011-05-20 109 views
3

我有问题让webshims插件画布polyfill工作。webshim polyfill画布将无法在IE7模式下工作

我收到以下错误IE9使用IE7模式:

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对象而不是上下文。

请帮忙吗?

+0

这里的该插件的主页: http://afarkas.github.com/webshim/demos/index.html – 2011-05-20 15:36:39

回答

1

我收到了插件作者,亚历山大·法卡斯下面的说明,通过电子邮件:

的问题如下。 Webshims 使用脚本 加载程序进行异步填充。这对现代浏览器中的性能 有好处。这也意味着, ,你必须等待,直到 画布功能准备就绪。

你的代码应该被包装在一个 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

相关问题