app里的CANVAS大小是否有限制?
我遇到的情况是——在调整CANVAS的height和width时发现,如果这两者的值是2407和2178,就可以在里面使用getContext画图,如果任一个值再加1,画图执行后虽然没报出错,但是也不执行画图指令。
{{{
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8">
<meta name="viewport" content="user-scalable=no, width=device-width" />
<style>
body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
background-color: #ddd;
color: #222;
font-family: Helvetica;
font-size: 14px;
}
</style>
<script type="text/javascript" charset="utf-8">
function init(){
var ooo=new myObj("paintDiv",2407,2178);/ 如果用此行的参数、注释下一行,就可以正常画图; /
//var ooo=new myObj("paintDiv",2408,2179);/ 如果用此行的参数、注释上一行,就不会画图; /
}
function myObj(sDivName,w,h){
alert([w,h]);
var tmpDiv=document.getElementById(sDivName);
this.RootDiv=tmpDiv;
this.RootDiv.style.position="relative";
this.RootDiv.style.overflow="hidden";
this.RootDiv.width=tmpDiv.width;
this.RootDiv.height=tmpDiv.height;
//绘图层CANVAS
this.paintCANVAS=document.createElement("CANVAS");
this.paintCANVAS.style.position="absolute";
this.paintCANVAS.style.top=0;
this.paintCANVAS.style.left=0;
this.RootDiv.appendChild(this.paintCANVAS);
this.paintCANVAS.height=w;
this.paintCANVAS.width =h;
var tmpCav=this.paintCANVAS.getContext("2d");
//alert(tmpCav);
tmpCav.fillStyle=("rgb(255,0,0)");
tmpCav.fillRect(0,0,this.paintCANVAS.clientWidth,this.paintCANVAS.clientHeight);
tmpCav.fillStyle=("rgb(0,255,0)");
tmpCav.fillRect(0,0,this.paintCANVAS.clientWidth/2,this.paintCANVAS.clientHeight/2);
tmpCav.fillStyle=("rgb(0,0,255)");
tmpCav.fillRect(0,0,this.paintCANVAS.clientWidth/4,this.paintCANVAS.clientHeight/4);
}
//setTimeout(init,1000);
</script>
</head>
<body onload="init();">
<div id="mainDiv" style='position: fixed;top: 0;left: 0;width: 100%;height: 100%;margin: 0;'>
<div id="contDiv" style='position: fixed;top: 0;left: 0;width: 100%;height: 100%;margin: 0;'>
<div id='paintDiv' class='myCanvas' style='position: fixed;background:#afafaf;min-height:600px;height:100%; background-repeat: repeat repeat;' ></div>
</div>
</div>
</body></html>
}}}
0 个回复