【问题标题】:KineticJS android stage sizeKineticJS android 舞台大小
【发布时间】:2013-02-06 01:01:50
【问题描述】:

定义 KineticJS 阶段我是这样的:

  var stage = new Kinetic.Stage({
    container: 'container',
    width: 320,
    height: 480
  });

所以舞台的宽度和高度是固定大小的。 如果分辨率不同,如何拉伸以适应手机屏幕?

【问题讨论】:

    标签: javascript android height width kineticjs


    【解决方案1】:

    嗯,这确实是一个 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.
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-07
    • 2012-12-13
    • 2014-06-01
    • 2016-12-13
    • 2014-01-23
    • 2013-07-02
    • 2012-11-22
    • 2012-10-30
    相关资源
    最近更新 更多