gpt4 book ai didi

javascript - Canvas 不随页面滚动

转载 作者:行者123 更新时间:2023-11-28 05:49:49 25 4
gpt4 key购买 nike

我的应用程序中有一个 Canvas ,它不会像我期望的那样滚动。我正在尝试制作一个体育比赛支架,所以我想要一个 DOM 结构,然后在其上覆盖一个 Canvas 以连接不同的比赛。在我必须滚动并且 Canvas 就像它的 position: fixed 一样工作之前效果很好。也许这是某种 flex 错误,或者我在做一些愚蠢的事情。我希望对 Angular 线与文本一起滚动。是什么导致了这种行为?

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>

最佳答案

position: relative; 添加到“main-view-container”类。

关于javascript - Canvas 不随页面滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37403900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com