宽高比图像调整时excanvas错误

宽高比图像调整时excanvas错误,canvas,internet-explorer-8,internet-explorer-7,html5-canvas,excanvas,Canvas,Internet Explorer 8,Internet Explorer 7,Html5 Canvas,Excanvas,下面的代码创建具有APEC比率的全屏图像。但这是不工作的ie与excanvas。我解决不了这个问题。有什么帮助吗 以下是JSFIDLE链接: 解决方案: 纵横比测试 函数GetWindowsSize(典型){ var myWidth=0,myHeight=0; if(typeof(window.innerWidth)=“number”){ //非IE myWidth=window.innerWidth; myHeight=window.innerHeight; }else if(docum

下面的代码创建具有APEC比率的全屏图像。但这是不工作的ie与excanvas。我解决不了这个问题。有什么帮助吗

以下是JSFIDLE链接:

解决方案:


纵横比测试
函数GetWindowsSize(典型){
var myWidth=0,myHeight=0;
if(typeof(window.innerWidth)=“number”){
//非IE
myWidth=window.innerWidth;
myHeight=window.innerHeight;
}else if(document.documentElement&(document.documentElement.clientWidth | | document.documentElement.clientHeight)){
//IE 6+处于“标准兼容模式”
myWidth=document.documentElement.clientWidth;
myHeight=document.documentElement.clientHeight;
}else if(document.body&(document.body.clientWidth | | document.body.clientHeight)){
//IE4兼容
myWidth=document.body.clientWidth;
myHeight=document.body.clientHeight;
}
如果(典型值=“宽度”){
返回myWidth;
}否则{
返回我的高度;
};
};
函数setupBackground(){
canvas=document.getElementById('myCanvas');
if(typeof window.G_vmlcavasmanager!=“未定义”){
canvas=window.G_vmlCanvasManager.initElement(canvas);
var ctx=canvas.getContext('2d');
}否则{
var ctx=canvas.getContext('2d');
};
函数绘图(){
画布宽度=0;
canvas.height=0;
var divWidth=getWindowsSize(“宽度”);
var divHeight=getWindowsSize(“高度”);
var yScale=divHeight/img.height;
var xScale=divWidth/img.width;
var newImgHeight=img.height*xScale;
var newImgWidth=divWidth;
如果(divHeight>=newImgHeight){
newImgHeight=垂直高度;
newImgWidth=img.width*yScale;
};
canvas.width=divWidth;
canvas.height=divHeight;
var diffX=(Math.max(newImgWidth,divWidth)-Math.min(newImgWidth,divWidth))/2;
var diffY=(Math.max(newImgHeight,divHeight)-Math.min(newImgHeight,divHeight))/2;
var imgX=0-diffX;
var imgY=0-diffY;
ctx.drawImage(img、imgX、imgY、newImgWidth、newImgHeight);
};
var img=新图像();
img.onload=函数(){
$(窗口).bind('resize',function(){
draw();
});
draw();
};
img.src=http://userserve-ak.last.fm/serve/_/460496/Popperklopper.jpg';
};

不确定这是否是您的问题,但在执行此操作时:

<!--[if IE]><script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script><![endif]-->
    <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

应该是:

<!--[if IE]--><script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script><!--[endif]-->
        <!--[if lt IE 9]--><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><!--[endif]-->

您将脚本记录在案,这样就不会在IE版本上工作,希望它能解决您的问题

<!--[if IE]--><script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script><!--[endif]-->
        <!--[if lt IE 9]--><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><!--[endif]-->