gpt4 book ai didi

html - webshim polyfill Canvas 无法在 IE7 模式下工作

转载 作者:可可西里 更新时间:2023-11-01 14:57:23 26 4
gpt4 key购买 nike

我在使用 webshims 插件 canvas polyfill 时遇到问题。

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

请帮忙?

最佳答案

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

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

关于html - webshim polyfill Canvas 无法在 IE7 模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6074167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com