第四章 移动端适配解决方案

function resizeCanvas(){ model = new createjs.EventDispatcher();//用来捕获事件的原型stageWidth = document.documentElement.clientWidth; stageHeight = document.documentElement.clientHeight; stageScale = stageWidth/(750/2); canvas = document.getElementById("canvas"); if(stageWidth/stageHeight >0.665) { stageScale = stageHeight/(1206/2); canvas.style.left = (stageWidth -750/2*stageScale)/2+ 'px'; } else { stageScale = stageWidth/(750/2); } canvas.style.width =750/2*stageScale + 'px'; canvas.style.height =1206/2*stageScale + 'px';}

在资源加载完成的回调方法中调用它

resizeCanvas();//自适应宽高

请看第五章

你可能感兴趣的:(第四章 移动端适配解决方案)