2011-05-20 108 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

相關問題