【问题标题】:How do I resize webGL canvas in bootstrap.js column?如何在 bootstrap.js 列中调整 webGL 画布的大小?
【发布时间】:2015-05-25 03:59:13
【问题描述】:

我在here 有一个网页,我想在其中使用bootstrap.js 库进行布局来调整HTML5 画布中的webGL 绘图以适应“6”列。

布局定义为:

<div class="container">
    <div class = "row">
        <div class = "col-md-2"></div>
        <div class = "col-md-6" id="rightColDiv"><canvas id="lesson04-canvas" style="border: none;" width="1000" height="500"></canvas></div>
        <div class = "col-md-2"></div>
        <div class = "col-md-2"></div>
    </div>
</div>

我在 tick() 函数中尝试了以下操作,但仍然没有得到我想要的尺寸。

function tick() {
    requestAnimFrame(tick);
    drawScene();

   //    gl.canvas.width = window.innerWidth;
   //    gl.canvas.height = window.innerHeight;

   // This is not returning a width
   var rightColDiv = document.getElementById("rightColDiv");
   var glwidth = rightColDiv.width;
//   gl.canvas.width = window.innerWidth - rightColDiv.width;
    gl.canvas.width = window.innerWidth * 6/12; // 6 columns out of the 12
    document.getElementById("lesson04-canvas").width = window.innerWidth * 6/12;
  // gl.canvas.height = window.innerHeight;

}

我认为问题是:

1) 当我使用 boostrap.js 库时,如何恢复“列”的宽度? 2) 我是否需要同时设置 gl.canvas.width 和“lesson04-canvas”的宽度? 3) tick() 函数是否是最合适的地方?

【问题讨论】:

  • 所以你只想让画布不超过 col div 的宽度?
  • 我希望画布的宽度和 webGL 的绘图区域等于
    的宽度

标签: javascript html twitter-bootstrap canvas webgl


【解决方案1】:

只需将以下内容添加到您的 css 中:

#rightColDiv canvas { 
  max-width:100%; 
}

那么它应该适合 col-md-6 div 的宽度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多