我不知道我是否为时已晚,但是您可以使用 div 标签包含画布标签。HTML:<div id = "viewport"> <canvas id="canvas"></canvas></div>CSS:#viewport{ overflow: hidden; //so you can't see outside of the div width: /*insert desired amount*/px; height: /*insert desired amount*/px;}Javascript:function scrollCamera(camx, camy){ var viewport = document.getElementById('viewport'); viewport.scrollTop = camy; viewport.scrollLeft = camx;}scrollCamera(x-/*desired amount*/, y-/*desired amount*/); //makes the camera follow the player