画布不会随页面滚动

时间:2016-05-24 03:29:06

标签: javascript css html5 canvas

我的应用中有一个画布,不会像我期望的那样滚动。我试图制作一个体育比赛支架,所以我想拥有一个DOM结构,然后在其上覆盖画布以连接不同的比赛。工作得很好,直到我必须滚动,画布就像它position: fixed一样。也许这是某种灵活的错误,或者我做了些傻事。我希望对角线能够与文本一起滚动。是什么导致了这种行为?



const c = document.getElementById('canvas');
const ctx = c.getContext('2d');
ctx.moveTo(0, 0);
ctx.lineTo(200, 200);
ctx.stroke();

.app-container {
  display: flex;
  height: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.app-nav-bar {
    flex: 0 0 230px;
    border: 1px solid #aaa;
    background: #eef1f7 no-repeat 0 100%;
    position: absolute;
    top: 0;
    bottom: 0;
    width: 200px;
}

.header-and-body {
    width: 100%;
    display: flex;
    flex-flow: column;
    margin-left: 200px;
}

.app-header {
  flex: 0 0 45px;
  border: 1px solid #aaa;
}

.main-view-container {
    display: flex;
    height: 100%;
    overflow-y: auto;
}

.tournament-container {
    margin-left: 20px;
}

canvas {
  position: absolute;
  z-index: -1;
}

.contents {
  height: 1000px;
  width: 1000px;
}

<div class="app-container">
    <div class="app-nav-bar">Navs</div>
    <div class="header-and-body">
      <div class="app-header">Header</div>
      <div class="main-view-container">
        <div class="tournament-container">
          <canvas id="canvas" width="1000" height="1000"></canvas>
          <div class="contents">
            <h4>Here are my contents</h4>
            <h4>Some other stuff</h4>
            <h4>This should scroll</h4>
          </div>
        </div>
      </div>
    </div>
  </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

position: relative;添加到&#34;主视图容器&#34;类。