设置 canvas 的高度以覆盖整个可滚动页面

Setting height of canvas to cover entirety of scrollable page

我的 canvas 元素当前具有以下属性:

var c = document.getElementById("c");
    var ctx = c.getContext("2d");

    //making the canvas full screen
    c.height = window.innerHeight;
    c.width = window.innerWidth;

当我将 canvas 放置在内容多于屏幕高度无法容纳的页面上时,canvas 会在我向下滚动时中断,这是可以预料的。如何更改高度 属性 以使 canvas 尽可能向下延伸到页面上的内容?

使用这个:

    var c = document.getElementById("c");
    var ctx = c.getContext("2d");

    //making the canvas full screen
    c.height = document.getElementsByTagName('body')[0].scrollHeight;
    c.width = window.innerWidth;