确定KineticJS第一阶段是这样的:
var stage = new Kinetic.Stage({
container: 'container',
width: 320,
height: 480
});
因此舞台的宽度和高度是固定的大小。 如果分辨率不同,如何拉伸它以适应手机屏幕?
答案 0 :(得分:2)
嗯,这真的是一个javascript问题。您希望使舞台的大小与窗口大小相同。这对我的android项目起作用了:
var stage = new Kinetic.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
});
修改强>
另外,我建议您添加jQuery,以便检查方向更改,然后您可以执行以下操作:
window.onresize = function(event) { //this function will resize your stage to the size of your window
stage.setWidth(window.innerWidth);
stage.setHeight(window.innerHeight);
stage.draw(); //redraw the stage, not sure if really needed, but good to have.
}
或者你可以这样做:
window.onresize = function(event) {
stage.setScale(x,y); //set x, y scale values when the orientation changes
stage.draw(); //redraw the stage, not sure if really needed, but good to have.
}