响应动力JS

时间:2014-03-27 10:53:57

标签: javascript twitter-bootstrap responsive-design kineticjs

我试图让我的Kinetic JS容器响应。目前这是我的代码。

    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.
    }

    var stage = new Kinetic.Stage({
        container: 'gamebox', // Find an HTML element
        width: window.innerWidth, // Set width
        height: window.innerHeight // Set heigth
    });

我没有获取浏览器窗口的innerWidth,而是希望获得div类的宽度,因为我使用Bootstrap。是否有可能,如果是这样,你怎么做?

编辑: 我终于通过将代码添加到此

来解决了我的问题
window.onresize = function(event) {  //this function will resize your stage to the size of your window
    stage.setWidth($('.col-lg-6').width());
    stage.setHeight($('.col-lg-6').height());
    stage.draw(); //redraw the stage, not sure if really needed, but good to have.
}
var stage = new Kinetic.Stage({
    container: 'gamebox', // Find an HTML element
    width: $('.col-lg-6').width(), // Set width
    height: $('.col-lg-6').height() // Set heigth
});

0 个答案:

没有答案